trying to decode RS485 protocol - protocols

I am trying to decode signal that two devices are using over RS485.
I captured signal, from which i got baud rate (57600, one bit is 17,3us long):
Screenshot of the signal
This signal is BIN: 0000000000010010001001111110011110011011111110...
Then i wrote simple capture program in arduino:
void setup() {
Serial.begin(57600);
Serial1.begin(57600);
}
void loop() {
if (Serial1.available()){
byte temp=Serial1.read();
if(temp==0){
Serial.println();
}else{
Serial.print(temp,HEX);
}
}
}
Which got me following output:
https://justpaste.it/6sw5g
What is my next step in decoding this communication?

Related

How to get ESP8266 to communicate with DF Player Mini [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 days ago.
Improve this question
Im using ESP8266 NodeMCU and im trying to send hex data via serial to DFPlayer Mini using the SoftwareSerial and DFRobotDFPlayerMini library. No matter what pin I use I keep getting errors.
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(0, 2); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void setup()
{
mySoftwareSerial.begin(9600);
Serial.begin(115200);
Serial.println();
Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
Serial.println(F("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!"));
while(true){
delay(0); // Code to compatible with ESP8266 watch dog.
}
}
Serial.println(F("DFPlayer Mini online."));
myDFPlayer.volume(10); //Set volume value. From 0 to 30
myDFPlayer.play(1); //Play the first mp3
}
void loop()
{
}
and this is the results i get
DFRobot DFPlayer Mini Demo
Initializing DFPlayer ... (May take 3~5 seconds)
Unable to begin:
1.Please recheck the connection!
2.Please insert the SD card!
and I've also tried changing the software serial library to ESPSoftwareserial. and I've tried different pins. I've tried other boards. I've tried using hardware serial instead. I've tried using this sketch with a different library
// this example will play a track and then
// every five seconds play another track
//
// it expects the sd card to contain these three mp3 files
// but doesn't care whats in them
//
// sd:/mp3/0001.mp3
// sd:/mp3/0002.mp3
// sd:/mp3/0003.mp3
#include <DFMiniMp3.h>
#include <SoftwareSerial.h>
// forward declare the notify class, just the name
//
class Mp3Notify;
// define a handy type using serial and our notify class
//
//typedef DFMiniMp3<HardwareSerial, Mp3Notify> DfMp3;
// instance a DfMp3 object,
//
//DfMp3 dfmp3(Serial1);
// Some arduino boards only have one hardware serial port, so a software serial port is needed instead.
// comment out the above definitions and use these
SoftwareSerial secondarySerial(14, 12); // RX, TX
typedef DFMiniMp3<SoftwareSerial, Mp3Notify> DfMp3;
DfMp3 dfmp3(secondarySerial);
// implement a notification class,
// its member methods will get called
//
class Mp3Notify
{
public:
static void PrintlnSourceAction(DfMp3_PlaySources source, const char* action)
{
if (source & DfMp3_PlaySources_Sd)
{
Serial.print("SD Card, ");
}
if (source & DfMp3_PlaySources_Usb)
{
Serial.print("USB Disk, ");
}
if (source & DfMp3_PlaySources_Flash)
{
Serial.print("Flash, ");
}
Serial.println(action);
}
static void OnError([[maybe_unused]] DfMp3& mp3, uint16_t errorCode)
{
// see DfMp3_Error for code meaning
Serial.println();
Serial.print("Com Error ");
Serial.println(errorCode);
}
static void OnPlayFinished([[maybe_unused]] DfMp3& mp3, [[maybe_unused]] DfMp3_PlaySources source, uint16_t track)
{
Serial.print("Play finished for #");
Serial.println(track);
// start next track
track += 1;
// this example will just start back over with 1 after track 3
if (track > 3)
{
track = 1;
}
dfmp3.playMp3FolderTrack(track); // sd:/mp3/0001.mp3, sd:/mp3/0002.mp3, sd:/mp3/0003.mp3
}
static void OnPlaySourceOnline([[maybe_unused]] DfMp3& mp3, DfMp3_PlaySources source)
{
PrintlnSourceAction(source, "online");
}
static void OnPlaySourceInserted([[maybe_unused]] DfMp3& mp3, DfMp3_PlaySources source)
{
PrintlnSourceAction(source, "inserted");
}
static void OnPlaySourceRemoved([[maybe_unused]] DfMp3& mp3, DfMp3_PlaySources source)
{
PrintlnSourceAction(source, "removed");
}
};
void setup()
{
Serial.begin(115200);
Serial.println("initializing...");
dfmp3.begin();
uint16_t volume = dfmp3.getVolume();
Serial.print("volume ");
Serial.println(volume);
dfmp3.setVolume(24);
uint16_t count = dfmp3.getTotalTrackCount(DfMp3_PlaySource_Sd);
Serial.print("files ");
Serial.println(count);
Serial.println("starting...");
// start the first track playing
dfmp3.playMp3FolderTrack(1); // sd:/mp3/0001.mp3
}
void waitMilliseconds(uint16_t msWait)
{
uint32_t start = millis();
while ((millis() - start) < msWait)
{
// if you have loops with delays, its important to
// call dfmp3.loop() periodically so it allows for notifications
// to be handled without interrupts
dfmp3.loop();
delay(1);
}
}
void loop()
{
waitMilliseconds(100);
}
this one is with a different library and differnt TX and RX pins.
and this is the error I get.
initializing...
Com Error 3
volume 0
Com Error 3
files 2
starting...
Any help with solving this would be greatly appreciated.

Sim800l save input as a string

I'm trying to save my received SMS into a string but it doesn't work. This is my error message :
recive_0_1:50:28: error: invalid conversion from 'int' to 'char' [-fpermissive] exit status 1 invalid conversion from 'int' to 'char'
[-fpermissive] This report would have more information with "Show
verbose output during compilation" option enabled in File ->
Preferences.**
#include <SoftwareSerial.h>
#include <string.h>
char message[160]; // max size of an SMS
char* text;
String data;
//Create software serial object to communicate with SIM800L
SoftwareSerial mySerial(4, 5); //SIM800L Tx & Rx is connected to Arduino #3 & #2
void setup()
{
//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
//Begin serial communication with Arduino and SIM800L
mySerial.begin(9600);
Serial.println("Initializing...");
delay(1000);
mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
updateSerial();
mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
updateSerial();
mySerial.println("AT+CNMI=1,2,0,0,0"); // Decides how newly arrived SMS messages should be handled
updateSerial();
}
void loop()
{
updateSerial();
}
void updateSerial()
{
// char c;
delay(500);
while (Serial.available())
{
mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
//char data=Serial.read();
//Serial.println(data,DEC);
}
while(mySerial.available())
{
Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
text=mySerial.read();
Serial.print(text);
//}
}
}
It looks like you're running into problems from trying to convert integers to characters. I use the below code to read from my SIM card to my SIM900 device:
1st: my software serial is defined and my setup script run:
SoftwareSerial gprsSerial(7, 8);
void setup()
{
pinMode(13, OUTPUT);
gprsSerial.begin(19200);
Serial.begin(19200);
delay(200);
// set up your AT COMMANDS HERE - I HAVE NOT INCLUDED THESE
}
Then I run my loop function as follows, calling the additional functions specified thereafter, :
void loop() {
readSMS();
delay(2000);
}
void toSerial(){
delay(200);
if(gprsSerial.available()>0){
textMessage = gprsSerial.readString();
delay(100);
Serial.print(textMessage);
}
}
void readSMS() {
textMessage = "";
gprsSerial.print("AT+CSQ\r");
toSerial();
gprsSerial.print("AT+CMGF=1\r");
toSerial();
gprsSerial.println("AT+CNMI=2,2,0,0,0\r");
delay(2000);
toSerial();
}
With the above you should not get any data type conversion hassles.

Processing/Bluetooth to Arduino

I want to light up a LED wirelessly through processing.
what I have so far.
I can (wirelessly) turn on my LED using a serial terminal called "Bluterm".
I can turn on my LED by pressing 1 or 0 to switch LED on and off in processing.
How can I leave Bluterm out of my equation and use processing to send the 1 and 0 through bluetooth.
Here is my code for processing:
import processing.serial.*;
Serial port;
String string;
void setup(){
String portName = Serial.list()[2]; //change the 0 to a 1 or 2 etc. to match your port
port = new Serial(this, portName, 9600);
port.bufferUntil('\n');
}
void draw() {
printArray(string);
}
void keyPressed() {
if (key =='1'){port.write('1');}
if (key=='0') {port.write('0');}
}
void serialEvent(Serial port) {
string = port.readStringUntil('\n');}
and the Arduino code
char data;
int led = 13;
void setup() {
pinMode(led, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available()>0){
data = Serial.read();
}
if (data=='1'){
Serial.println("HELLO");
digitalWrite(led, HIGH);
}
else if (data=='0'){
digitalWrite(led, LOW);
Serial.println("BYE");}
}
I'm kind of lost, can processing talk to bluetooth or do I always need a terminal?
If something isn't clear pls don't hesitate to ask,
Thank you for your time,
Juriaan
The Processing code makes sense.
It could do with a bit of formatting and error checking, but it's all pretty much there:
import processing.serial.*;
Serial port;
String string = "";
void setup() {
String portName = Serial.list()[2]; //change the 0 to a 1 or 2 etc. to match your port
try{
port = new Serial(this, portName, 9600);
port.bufferUntil('\n');
}catch(Exception e){
e.printStackTrace();
}
}
void draw() {
background(0);
text(string,10,15);
}
void keyPressed() {
if(port != null){
if (key =='1') {
port.write('1');
}
if (key=='0') {
port.write('0');
}
}
}
void serialEvent(Serial port) {
string = port.readString();
if(string == null){
println("null serial string");
string = "";
}
}
The Arduino code looks legit too.
What's unclear is what Bluetooth module you're using and how you're setting it up.
For example, if you're using something like BlueSmirf, be sure to use the guide
supplied.
The main points are:
Make sure you're using the SerialPortProfile (SPP) Bluetooth Profile
Double check you're wiring: the way your Arduino code reads you would be connect BT module's TX to Arduino's RX pin 0 and BT module's RX pin to Arduino's TX pin 1. Note you may want to do that after you upload your firmware with Arduino (as pin's 0 and 1 are Arduino's hardware Serial), otherwise goto point 3 :) (recommeded)
If you use an Arduino with multiple hardware serial ports (like Arduino mega) go with those (e.g. Serial1 instead of Serial) otherwise use a SoftwareSerial library with a low baud rate (like 9600), avoiding high baud rates.
Update
The HC-05 module uses 3.3V logic, while the Arduino uses 5V logic.
Uses a bidirectional 3.3V <-> 5V logic level converter or resistors, otherwise you risk frying your HC-05 module:
A quick search returns a detailed HowToMechatronics.com Arduino and HC-05 Bluetooth Module Tutorial
i see u are using a hc05 bluetooth device i have this myself but i dont really get what u want to use for sending the 1 and 0 to your hc05 and are you only using a led becouse if it is i would be able to help on (if you wanna send the bluetooth signals with a mobile app try the blynk app fron app store or google play store)

Bluetooth module HC-06 is not responding to any AT command on Arduino

Arduino Uno R3, HC-06. There's no response to the AT commands on the serial monitor.
I want to establish Bluetooth communication between PC and Arduino. At first I had to change the baud rate from 9600 to 115200, and the AT+BAUD8 command was working well. But after that change AT commands are not working. I cannot see any respond on the serial monitor.
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2, 3); // Bluetooth module Tx:Digital 2 Rx:Digital 3
void setup() {
Serial.begin(9600);
BTSerial.begin(9600);
Serial.println("ATcommand"); //ATcommand Start
}
void loop() {
if (BTSerial.available())
Serial.write(BTSerial.read());
if (Serial.available())
BTSerial.write(Serial.read());
}
I used the above simple code and also I've already checked the Tx, Rx pins.
What I want to do in the end is Bluetooth communication with a PC as a master and an Arduino as a slave.
Is it possible to upload code to Arduino through Bluetooth?
This code works for me:
#include <SoftwareSerial.h>
SoftwareSerial BT(10,11); // TX to pin_10. RX to pin_11 of Arduino.
void setup() {
Serial.begin(9600);
BT.begin(9600);
}
void loop() {
if(Serial.available()) {
String command = Serial.readStringUntil('\n');
Serial.println(command);
BT.print(command);
}
if (BT.available()){
String retorno = BT.readStringUntil('\n');
Serial.println(retorno);
}
}
Serial Monitor with New line.
AT
AT+VERSION
AT+NAMEmy_blue
AT+BAUDx

Arduino transmission Data by HC-05(Bluetooth)

platform:Arduino UNO, Arduino Mega2560, HC-05
Here shows the detail.
In Arduino UNO(Master), I encode
Serial.print("A 1 2 3 4 5;");
In Arduino Mega2560(slave), I encode
void setup()
{
//connect to the PC
Serial.begin(9600);
//connect to the Arduino UNO(By bluetooth)
Serial1.begin(38400);
}
void loop()
{
//its value > 0
Serial.println(Serial1.available());
//output : 128 or 248
Serial.print(Serial1.read());
delay(1000);
}
The value of Serial.available() > 0 is true,
but the print result of Serial.print(Serial1.read()); is abnormal. it print
I want to know the reason and its solution.Thanks!
I'm assuming that you made sure that both the Bluetooth devices are connected properly and the baud rates are matched.
Now, one problem might be the buffer might be full. On the sender's side, provide a delay equal to or slightly higher than the delay on the receiver's side.
Next, on the receiver side, change void loop to this:
void loop(){
if(Serial1.avaialable() > 0){
char value = Serial1.read();
Serial.println(value);
delay(1000);
}
}

Resources