I have been working on a project where I am doing some image processing using python, OpenCV package. After processing, I need to send the data from python script to Arduino connected to the system. From this Arduino, a NRF24L01 is connected which transmits the data to another Arduino which is doing some job.
I have tried the pyserial package and went through lot of different blogs. I can communicate the between the python script when there is no nrf24l01 but when I connect the same, couldn't receive anything on the other end.
Any help on this will be greatly appreciated.
Thank You
nitinsaini2909:
I have tried the pyserial package and went through lot of different blogs.
The pySerial package is ok, but it's a pretty low level processing package. I suggest using a Python package designed for communicating with Arduinos specifically: pySerialTransfer. This package will automatically packetize/parse serial data packets between Python and Arduinos.
To install:
pip install pySerialTransfer
Example Python code:
from pySerialTransfer import pySerialTransfer as txfer
if __name__ == '__main__':
try:
link = txfer.SerialTransfer('COM13')
link.txBuff[0] = 'h'
link.txBuff[1] = 'i'
link.txBuff[2] = '\n'
link.send(3)
while not link.available():
if link.status < 0:
print('ERROR: {}'.format(link.status))
print('Response received:')
response = ''
for index in range(link.bytesRead):
response += chr(link.rxBuff[index])
print(response)
link.close()
except KeyboardInterrupt:
link.close()
The pySerialTransfer library has an Arduino compatible library, SerialTransfer.h. This library also packetizes/parses serial data packets from Python and other Arduinos.
To install:
Download and install via the Arduino IDE's Libraries Manager (search "SerialTransfer")
As suggested I tried the pyserialtrasnfer and serialTransfer.h as u suggested but no help. Also, the python script opens the serial com port for the Arduino connected to the system. So, I cannot see if the data is been received by the same Arduino to the system. but I was transferring data to through nrf to the other Arduino to receive and display it on the system via the serial monitor.
the code I was using earlier on python script was
import serial
trans = serial.Serial("/dev/ttyUSB0", baudrate=9600)
data = "2"
trans.writ
from this code, I was able to transfer the code to the Arduino and toggle the LED on pin 13.
but when I try to transfer the same Through nrf after initializing it, couldn't receive anything on the other end.
Arduino transmitter code I was using is
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
//Byte of array representing the address.
//This is the address where we will send the data. This should be same on the receiving side.
void setup() {
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
Serial.begin(9600);
char data = '3';
}
void loop(){
char data = '3';
while(Serial.available() > 0){
data = Serial.read();
}
radio.write(&data, sizeof(data));
}
Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.
The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work
There is also a connection test program to check that the Arduino can talk to the nRF24 it is connected to.
A common problem with nRF24 modules is insufficient 3.3v current from the Arduino 3.3v pin. At least for testing try powering the nRF24 with a pair of AA alkaline cells (3v) with the battery GND connected to the Arduino GND.