Sending and recieving data between three arduinos connected trough RS485 - arduino

I have connected three arduino's togheter trough a RS485 BUS. Two arduino's use the MAX485 chip and the other arduino the MKR 485 shield. They are wired in a half-duplex. The goal is to be able for all devices to both listen and talk on the bus. When I am only transmitting data from one device to the other two devices, all the data is being recieved. However, when an other devices is also sending data, some of the data seems to get lost.
The two arduino's using the MAX485 are programmed with the softwareSerial lib. :
//reading
digitalWrite(Enable_pin, LOW);
while(softwareSerial.available()){
read_val = softwareSerial.read();
}
digitalWrite(Enable_pin, HIGH);
//writing
digitalWrite(Enable_pin, HIGH);
softwareSerial.write(data);
digitalWrite(Enable_pin, LOW);
The arduino using the MKR 485 shield is programmed with the ArduinoRS485 lib.:
//reading
RS485.receive();
while(RS485.available()){
read_val = RS485.read();
}
//writing
RS485.noReceive();
RS485.beginTransmission();
RS485.write(data);
RS485.endTransmission();
RS485.receive();

Related

AT-Commands from ESP32 to Fanstel BC805M (nRF52805M) not working

I want to send a simple AT-Command like: AT\r\n from the ESP32 to the Fanstel BC805M (nRF52805M) breakout board. My goal is to get an answer.
Problem: The Esp32 does not get an answer from the BC805M.
Setup
Hardware
The ESP32 is connected by usb cable to my Mac.
The ESP32 connects to the BC805M by five cables -> 3V3->VDD, GND->GND, Rx->Tx, Tx->Rx, GPIO32(high)->GPIO04(P004). Rx and Tx from ESP32 are Serial2 (not the Serial0 of the programmer). The P004 pin from BC805M is set to high to enable "command-mode".
Software
The BC805M came already preloaded with The AT commands code.
The ESP32 is flashed by a simple Serial2 write/read arduino code:
#include <HardwareSerial.h>
#define RXD2 16
#define TXD2 17
#define CMD_MODE 32
void setup() {
Serial.begin(115200);
Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2);
pinMode(CMD_MODE, OUTPUT);
digitalWrite(CMD_MODE, HIGH);
delay(1000);
Serial.println("start");
}
void loop() {
Serial2.write("AT\r\n");
delay(500);
if(Serial2.available()){
Serial.write(Serial2.read());
}
}
On Monitor, I received nothing: Terminal Output
What I tested
I connected the two ESP32 Rx and Tx Serial2 Pins with each other and the monitor prints AT AT AT ... (so this works)
I connected the ESP32 with the BC805M not by crossing Tx and Rx but like: Rx->Rx, Tx->Tx; I received the message
BlueNor 200622 started
on my monitor. This means I read the values of the Rx pin of the BC805M and wrote them to my monitor. Shouldn't this message be sent on on the Tx pin of the BC805M?
I connected to the BC805M per Android App, which connects to it via Bluetooth Low Energy. I sent commands from the app to the BC805M. But I got no response. I could read the commands I sent on the Rx Pin of the BC805M.
I connected solely the BC805M per usb to my mac and ran Arduino-IDE's monitor, the monitor prints absolutely nothing and writing AT-Commands also results into nothing.
The Fanstel support just wrote me that the BC805M Evaluation Board is NOT preloaded with the AT-Command firmware.
Only the BC805M module has it preloaded.
That explains why the AT-Commands did not work.

SIM 800L cannot connect to at

I am trying to send some data using the sim800l module.
I am using the SoftwareSerial library and connected the RX and TX pins to Digital pins 10 and 11. I have also tried pins 2 and 3.
The module is connected to a 5v power supply and the only pins connected to the Arduino board are RX and TX.
The module is connected to the network.
this is the code I am using:
#include <SoftwareSerial.h>
SoftwareSerial myGsm(10,11);
void setup()
{
myGsm.begin(9600);
Serial.begin(9600);
delay(500);
myGsm.println("AT+CGATT=1");
delay(200);
printSerialData();
myGsm.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");//setting the SAPBR,connection type is GPRS
delay(1000);
printSerialData();
myGsm.println("AT+SAPBR=3,1,\"APN\",\"\"");//setting the APN,2nd parameter empty works for all networks
delay(5000);
printSerialData();
The problem is that nothing gets printed in the serial monitor.
I used the module to send sms messages using the FONA library and it worked.
Please help!
I think the problem is,
To print something on the serial monitor, you need to use the Serial.println();
The softwareSerial println only sends data to the devices connected to that pins.

RFID reader connected to NodeMCU via RS485 - Not Working

I want to connect a long range RFID card reader unit to NodeMCU (12E) board and read the card number. The RFID reader board has a RS485 output port and when I connect this board to my laptop using a RS485 to USB converter, I get the card number using a RealTerm/CoolTerm program.
I was just wondering how I can directly connect the RFID reader board to NodeMCU and read the card number.
I did the following so far, any help in this regard will be much appreciated -
Connected RFID board with a RS485 to USB converter
Used a female to female USB connector and connected (1) with NodeMCU at the other end(via micro usb port on NodeMCU)
Written a very simple arduino sketch to read the serial data as -
#define BUZZER 4
void setup() {
Serial.begin(9600); // Init Serial
}
void loop(){
if (Serial.available())
{
tone(BUZZER, 5000);
delay(1000);
noTone(BUZZER);
}
}
However, the buzzer gives no sound.
My questions are -
Is this the right way of reading data from the card reader via RS485 port ?
Why the data is not received in NodeMCU while I can see it on the terminal program on my laptop
Is there any arduino sketch that I can refer to to read the card number in NodeMCU ?

Xbee explorer in pc communication with Xbee in arduino

I have a Xbee explorer on the pc, and one arduino with the arduino wireless shield with another Xbee there. Using XCTU I can receive data from the arduino to the PC but not the other way around, sending using XCTU to the arduino.
If I send from the XCTU only the led RSSI from the arduino wireless shield is on but it should be the RX led.
This is the tutorial I'm using Link
Here's the code I'm using on the arduino, booth antennas are S1 Xbee antennas and the antennas are all default values restore
// We'll use SoftwareSerial to communicate with the XBee:
#include <SoftwareSerial.h>
SoftwareSerial XBee(10,11); // RX, TX
void setup()
{
// Set up both ports at 9600 baud. This value is most important
// for the XBee. Make sure the baud rate matches the config
// setting of your XBee.
XBee.begin(9600);
Serial.begin(9600);
}
void loop()
{
if (Serial.available())
{ // If data comes in from serial monitor, send it out to XBee
Serial.println("first if");
XBee.write(Serial.read());
}
if (XBee.available())
{ // If data comes in from XBee, send it out to serial monitor
Serial.println("second if");
Serial.write(XBee.read());
}
}
Please precise the operating mode on your two xbee modules thier model( it can be hard to communicate when using XBEE3), and their DL, DH

xBee communication Arduino to Arduino

I have a realy weird problem with my xBee S1 Pro moduls. I used the XCTU software to configure them. I set one Arduino to recive data and the other one to transmit. When i use the XCTU Software to send some testframes, it works, the reciver gets the data. But if i want my arduinos to communicate it dosent work. I assume that the moduls are configured the right way because PC -> Arduino works. So i'll provide the Sketches so you can tell me whats going wrong
reciver
void setup()
{
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop()
{
if(Serial.available() > 0){
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
Serial.print("recived some data: ");
Serial.println(Serial.read());
Serial.flush();
}
}
and now the sender
void setup()
{
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop()
{
Serial.println("data");
Serial.flush();
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(4000);
}
whats wrong? any ideas?
I would check the connections to the Xbee, i.e. make sure that RX is actually connected to DOUT and TX is connected to DIN. Also if you are sending actual "Frames" then it sounds like you are running your xbees in api mode so you will need to do more then just send out "data" what you want is for it to be running in serial pass through mode.
One last thing to check is if you are using arduino Leonardo or Micro the hardware Serial port is Serial1 not Serial.
You're using the same Serial port for communicating with XBee and USB. That's the problem. You need to set another Serial port instead of the used for USB to communicate with XBee.
It will be good if you share what arduino boards and shields you are using.
So first thing is first... If these xBees have separate passcodes at a different baud rate, shit is going to happen. Also what command mode are these in (AT or API)? Factory default settings ? Accepting AT commands to change these ? (By default you are in AT mode)
Open a serial program (I use coolTerm for OS X ). Ensure to setup correctly of these steps.
Once you know these transmitters are talking at the same baud, passcode, etc... Ensure you have the code uploaded to your Arduinos BEFORE connecting these transmitters to the RX/TX pins with a simple serial read and write.
The code seems right, but make sure what you are trying to send. Xbees can transmit and receive 8bit data only.
First send a known byte of data such as a=100; and see whether this data receives there perfectly or not.

Resources