How to setup Xbee without X-CTU(official tool) - raspberry-pi

I try to make two raspberry pi communicate (text) with each other via XBee S2 module. Instead of using XBee shield, I connected XBee and pi with dupont lines(PIN: 3.3V, Tx, Rx, Ground).
Under pi, install minicom and
minicom -b 9600 -D /dev/ttyAMA0
I could enter XBee command mode, where I got reply 'OK' when I type some commands. My test architecture is shown below.
(C)PI-XBee (R)XBee-PI
I set same PANID and destination address as source address of each other. However, I cannot get the message from each other in minicom.
Did I miss something? Or I did need to setup with X-CTU.

Did you exit command mode before sending data (I think the command is ATCN, or just let command mode time out)? Are the modules joined to the same network? Check AI (association indicator, should be zero), SC (scan channels, identical on both modules), CH (channel) and OI (operating PAN ID). The read-only CH and OI should be the same on both modules if they're on the same network. Use ATNR to reset the network on the coordinator, and then on the router to force it to rejoin the network. Be sure to use ATWR to write your settings if you want them to stick after power cycling.
Edit: Turns out both modules had Router firmware installed, so they were both trying to join a network. The S2B has different firmware files for Coordinator and Router/End Device node types. The S2C has a single firmware and uses the setting of ATCE to select coordinator (1) or router/end device (0) operation.

Related

How to send data between two already configured HC-05 modules pi pico

I'm building an small project in which I'd like to send information from a master HC-05 bluetooth module to an slave one (both of them connected to different pi pico's), I've already synced them following Bluetooth HC-05 master-slave configuration using CircuitPython tutorial, I've finished the set up and now both modules (master and slave) seem to be properly connected, now the problem is that I don't know how to send data from one to the other.
All the tutorials that I've found that imply bluetooth communication seem to do it from a mobile Android app to the slave module, but what I'd like to do is to read data from an analog joystick with one pi pico and send it to through my master HC-05 the slave module (which would be connected to another pico) and then control an electric motor with this received data.
As I understand, the configuration process was finished in CircuitPython but this DOES NOT obligate me to continue with CircuitPython, I mean, I could do my implementation with microPython for example as Circuit Python was used only for the configuration process, is this correct?
My main question is, what is the library/process I could use to send data from master module to slave module?
Pd: I know there is a Raspberry Stack Exchange site but I posted my question here for visibility and also it is related to software too!.

Will an I2C device get detected when it is connected to Raspberry Pi when there is no Driver and dts related to it?

I'm in confusion that will an I2C device get detected in raspberry pi even when there
are no device drivers and DTS files related to it.
Will it show up when we use this command
ls /dev/i2c-*
and are we able to detect its address when I try to probe using
i2cdetect -y bus_number
In short:
... when there are no device drivers and DTS files related to it.
Will it show up when we use this command
ls /dev/i2c-*
No. This command will list available I2C buses, not devices.
and are we able to detect its address when I try to probe using
i2cdetect -y bus_number
Maybe. In most cases yes.
A bit more elaborated:
Depending of what kind of I2C device it is, and what you want to do with it, you might still be able to communicate with it.
driver - best case
If you have relevant device tree change to describe this I2C device (on what bus it is located, its address, extra signals if needed - like interrupt pin, etc) and associated driver is present (built-in or as a module, check *_defconfig options in Linux kernel source) - driver should probe device during either boot or manual module loading.
Why best case? If you have a driver you don't have to think about protocols and programming, and, as an example, reading a value from ADC device might be as simple as:
root#pi:~# cat /sys/bus/iio/devices/iio:device0/in_voltage0_raw
291
i2ctools
Another approach would be to use i2cget/i2cset tools from i2ctools package. No device tree changes needed. With these tools you can talk with any unclaimed I2C device on any enabled I2C bus in device tree.
You'll need to implement communication with I2C device by your own. From security and stability perspective - IMO this is the worst case to go, but is good for hardware debugging and, in some cases, initial bring-up.
Example is here.
Note regarding i2cdetect - this command tries to detect devices on particular bus, but gives no warranty. As per man i2cdetect:
As there is no standard I2C detection command, i2cdetect uses arbitrary SMBus commands (namely SMBus quick write and SMBus receive byte) to probe for devices.

Passive WiFi detection system using WiFi router

As part of my project requirement I want to make a system which will detect all the WiFi devices in my router range either its connected or not, I did some research on it then I found something like wireshark ,kismate etc I just tried the wireshark by making my Mac machine's WiFi as an adhoc network and its all fine I am able to list all the WiFi devices in wireshark, now I want to make a real-time system based on a real WiFi router I don't know how I will configure my router using my PC and how I will monitor the router from my PC , one more thing if I am using this wireshark how I will use this data for my requirement. If any one worked with similar scenarios please help me..thanks in advance
To do that you will need more than the usual API that you have on commercial WiFi routers (by that I mean a full SSH access). I would:
flash my router with OpenWRT (you can search for your router on this page for detailed instructions)
Install the aircrack-ng suite on the flashed router with
opkg update
opkg install aircrack-ng
Put my WiFi card in monitor mode and run the airodump service:
airmon-ng start wlan0 #Put your NIC in monitor mode
airodump-ng mon0 #Sniff surrounding packets
You don't necessarily have to install aircrack-ng, you can just put your card in monitor mode using command line (look at the documentation for your WiFi driver) and then run tcpdump (command line equivalent to wireshark) but aircrack works very well and has a nice format.
Also, I should warn you that you can brick your router by flashing it. I never had such a problem when flashing router mentioned on the OpenWRT wiki and there are (most of the times) ways to restore a bricked router depending on the brand but I am not responsible if you break it ;)

What is the AT command to reset USB cellular modem?

What is the AT command sequence used to reset a USB cellular modem?
Is there a single AT command that can be used? Or does it require a sequence of several in order to reset a USB cellular modem?
I have a Huawei E272 and E220 however I am also interested in a general command sequence if there is any standard AT command.
Resetting the modem is a manufacturer-specific AT command.
There is a spec available online for Huawei AT commands here.
Look at section 3.10 +CFUN
The EXECUTION command is used to set the MS mode or restart the MS
AT+CFUN has 2 parameters:
AT+CFUN=[fun[,rst]]
These 2 parameters fun and rst are defined as follows:
fun:
0 Set as minimum functionality mode (set the RF off but keep
the SIM power on, previous mode must not be offline)
1 Set as online mode (default value) (previous mode must not be offline)
4 Set as offline mode (previous mode must not be FTM)
5 Set as offline FTM (previous mode must be online)
6 Reset MS (previous mode must be offline)
7 Set as RFoff mode (about radio frequency)
rst: Whether to restart MS before setting
0 Not restart MS before setting. (Default)
1 Restart MS before setting. (fun must be 1)
There seems to be a generally used or defacto standard AT command for turning off and turning on a USB cellular modem.
To turn the modem off use: AT+CFUN=0 and to turn the modem on use: AT+CFUN=1. The AT command must be terminated by a carriage return and it must be sent through the Virtual Serial Port that is assigned to the USB modem.
I used the following procedure to test with a PANTECH UML290 USB cellular modem with Verizon as the carrier.
First step was to determine the Virtual Serial Port in use through which I would send the AT commands. I used the Device Manager application from the Control Panel to find the USB modem and to then see what COM port it was using.
Next I used the HyperTerm application to open a connection to the Virtual Serial Port assigned to the USB modem as shown in Device Manager. The HyperTerm application is an older modem and serial ports application that came with Windows XP and earlier. For Windows 7 and later see HyperTerminal Alternatives for Windows 7.
I then used AT+CFUN=0 to turn off the USB modem. Then I used ipconfig /all to examine the LAN adapters in my system which showed the PANTECH UML290 as "Media disconnected"..
I then used AT+CFUN=1 to turn the USB modem back on. I used the ipconfig /all command to display the status of the LAN adapters in my system. After using the command a second time after a few seconds wait, the displayed status showd the PANTECH UMO290 up and running..
For a fuller description of the AT+CFUN=0 command see page 12 of AT Commands GSM Reference Guide from MultiTech Systems which has this to say:
This command selects the mobile station’s level of functionality. When
the application wants to stop the product with a power off, or if the
application wants to force the product to execute an IMSI DETACH
procedure, then it must send: AT+CFUN=0 (equivalent to AT+CPOF). This
command executes an IMSI DETACH and makes a backup copy of some
internal parameters in SIM and in EEPROM. The SIM card cannot then be
accessed. If the mobile equipment is not powered off by the
application after this command has been sent, a re-start command
(AT+CFUN=1) will have to issued to restart the whole GSM registration
process. If the mobile equipment is turned off after this command,
then a power on will automatically restart the whole GSM process. The
AT+CFUN=1 command restarts the entire GSM stack and GSM functionality:
a complete software reset is performed.
This description appears to apply to how this AT command is generally implemented by USB cellular modem providers.
Addendum I: Command Line Utility
I wrote a simple command line utility with Visual Studio C++ that can be used to send a command string to a serial port. The source is located in my Github repository at https://github.com/RichardChambers/writereadport
The utility can be used in a shell or command file and has both a command line interface for a single AT command or a console mode. It is primitive but does the job I needed at the time.
ITU V250 (https://www.itu.int/rec/T-REC-V.250-200307-I/en) specifies ATZ as beeing the reset command:
6.1.1 Reset to default configuration
Syntax
Z[< value>]
Description
This command instructs the DCE to set all parameters to their factory defaults(...)
If you issue the command ATZ, you should have you modem reset and get an OK. Read the spec for more information about the <values> parameter if needed.

Serial communication with Raspberry pi

How can we do serial communication using the raspberry pi with a python script to send/receive data to my laptop? If yes can we use the RS232 cable to connect to the TX/RX ports on the raspberry pi directly? If yes, what pins must be used from the RS232 cable? It would be help full if anyone can post a example python script?
Since my first aim is to send/receive data to the laptop to/from the raspberry pi, i'm using a RS232 to USB cable at both end to connect to the laptop as well as the raspberry pi.
RS-232/RS-485 to PC and USB to PC
For RS-232
1) Download Putty.
2) Buy a Serial Port RS232 to TTL Converter Module and a RS-232 serial cable for PC.
3) Follow the steps in Connection to a microcontroller or other peripheral on this
link. Actually read the whole thing for better understanding.
4) Power your converter module with either 3.3V (pin 1) or 5.0V (pin 2), connect Rxd pin of the module to Rxd (pin 8) on Rpi and Txd pin to Txd (pin 10) on Rpi.
5) Connect your RS-232 (from PC) cable to the converter module
Now you are ready to do some coding in Python. But before that make sure that you have the library called serial for python to create the communication. You can easliy get it via terminal by typing sudo apt-get install python-serial. Also you will see the baudrate in the code is 7200. It could be less or more depending on the synchronization. Also make sure that baudrate should be same in putty and COM1, which is the port that RS-232 is connected to your PC. You can check and set it from device manager in Windows. By the way, timeout is the time gap between each message you are receiving.
In case you can't run the code from idle (that happens for some libraries), do it in terminal. For that go to the folder where you keep your python code and type python name.py.
import serial
import time
def readlineCR(port):
rv = ""
while True:
ch = port.read()
rv += ch
if ch == '\r' or ch == '':
return rv
port = serial.Serial("/dev/ttyAMA0", baudrate = 7200, timeout = 2)
while True:
rcv = readlıneCR(port)
port.write("I typed: " + repr(rcv))
print(rcv)
For USB serial to PC
You have two options
First, you can buy a USB dongle for RS-232/RS-485 so that you would not use GPIO pins. But it is better to get a USB hub for all mouse, keyboard and dongle.
Second and easier, you can buy a FTDI USB to TTL converter and use GPIOs to have a serial communication with Rpi. The code for this is exactly the same the one with above. Connection for this is easy.
Module -- Rpi
Txd -- > Txd
Rxd -- > Rxd
Gnd ---> Gnd
Are you trying to issue commands to the Raspberry Pi? (like a console?) I would suggest a plain jane 3.3V FTDI cable. You can get them from Digikey or Sparkfun. Note: the Raspberry Pi runs on 3.3V so you must be sure that anything you connect to it is running 3.3V or has a level shifter. See more information about level shifters here. (go down to the Logic voltage levels section)
First, you need to make sure that Raspbian has released the serial console. You can do that with the script located here.
If you're more interested with communicating with other devices then maybe the following suits you:
Do you have an Arduino? You can run a simple test by putting this sketch on your Arduino:
#define SERIAL_BAUD 115200
void setup() {
//Init serial connection
Serial.begin(SERIAL_BAUD);
Serial.setTimeout(1);
}
void loop() {
if ( Serial.available() ) {
byte type = Serial.read();
Serial.write(type);
}
}
And wire it up using the following diagram:
Note: make sure you don't connect a usb cable to the Arduino. It will be powered by the Raspberry Pi.
You can then install and run screen. Screen is a dead simple way of connecting to a serial port.
apt-get install screen
Then run the following:
screen /dev/ttyAMA0 115200
The screen will show up blank. But, when you start typing you will notice that the characters you're writing are getting looped back to your terminal.
Note: If the screen is still blank you should double check the connections (power led on the Arduino is a good thing to check).
When in doubt you can see my whole example here.
The Raspberry Pi's serial port uses 3.3v logic; RS232 uses 12v, so a level shifter would be needed to use those pins so you cannot use RS232 directly.
Serial interfacing in Python using the PySerial module (http://pyserial.sourceforge.net) it is pretty straightforward to send and recieve data. There are examples in the documentation, but essentially to send data:
import serial
port = serial.Serial(portname, baudrate, timeout)
port.write("message to send")
port.close()
It depends what you're doing with the data and what sort of data you're recieving to decide the best way to recieve data, but a very simple example:
import serial
port = serial.Serial(portname, baudrate, timeout)
data = port.read(numberofbytes)
print data
This simply waits until the number of bytes specified has been retrieved or the timeout value is reached.
You can use port.inWaiting() to return how many bytes are currently in the buffer.
you should install python library for serial drivers. you can not use rs232 directly, instead you can use a max232 chip in between rx(gpio15) tx(gpio 14) pins and your usb to serial converter. or you can use usb to ttl serial cable from adafruit. here is the link for setup : http://learn.adafruit.com/adafruits-raspberry-pi-lesson-5-using-a-console-cable/overview
Serial Communication in Raspberry pi.
There are plenty of options for serial communication
Use Visual GDB Plugin in visual studio and deploy code remotely in raspberry pi
and loop back the txd and rxd pins and check if the send message is received or not.
If you are familiar with java Install pi4j and in the example folder there is a sample program , compile and run using terminal. and check the output.
if you are connecting using RS232 and Max232 , please note that uses 3.3 volt not 5 or 12v. , it may burn your board.