Software Serial Libraries not working . Can any one share me code to read RS485 to TTL data reading of a sensor by modbus library and SoftwareSerial library???
Do you need to use SoftwareSerial ?
How many hardware Serial ports does the SAMD21 have ?
Could be helpful to the forum if you tell us what actually happens, what errors you get or what does not work.
The SAMD21 does have several hardware serial ports.
Whats a RD485 ?
For some context, I believe that this is a follow on to an earlier discussion here:
If i install Vega SerialSoftware library by CDAC, it has some header files , which are missing and not redirecting , when after right click i "Click goto definition". Sry it is RS485 modbus, just mis typed in previous comment
Yes markd833 , i am not able to read the data. All connections i made as you mentioned . Can you provide me sample example snippet to read it?
It is not the case weather libraries working or not. But i needed too quick solution to read that data. I will be very thankful to you . it is very important for me in short duration , bz next 3 days we will recieve our custom boards.
I think that the SAMD21 processor you have is also used by the official Arduino MKR series of boards. That series also has a MKR485 board.
The ArduinoModbus library documentation for the MKR series is here:
The library includes RTU examples to get you going.
You need to study the SAMD21 MKR board pinout and the MKR485 board schematic to see where the serial connections go as well as the directional control signals for the RS485 line driver/receiver. You then need to cross-reference that with the pinout of the SAMD21 board you have to make sure that you are using the correct pins - which may not necessarily be in the same positions on the headers as they are with the MKR series of boards.
Do a search for atsamd21 multiple serial ports - Google Search
E.g. Overview | Using ATSAMD21 SERCOM for more SPI, I2C and Serial ports | Adafruit Learning System
I didn't think the SAMD21 even had a softwareSerial library.
Since it can support up to 6 hardware Serial ports, you shouldn't need SoftwareSerial!
(although, I suppose that this is of little comfort if you've designed a board that needs to speak Serial on pins that aren't connected to a Hardware Serial...)
I have seen some RTU examples , eg Temperature& Humidity sensor modbus example code, but there is no pin assignment in example . From where it is reading the temperature humidity data.
Which example is most suitable for my water level detection sensor. Can you glimpse some light into it?
the RX/TX pins are Serial1
I don't think you will see any pin assignments as the MKR series of boards are all designed to just plug together keeping all the wiring side "hidden". When you use another vendors board, you have to do your own detective work. Start by finding a schematic of your SAMD21 board.
SAMD21 RS485 Board
VIN VCC
GND GND
D0 RO *** (See below)
D1 DI
D2 RE } These 2 can be any digital
D3 DE } output capable pins
RS485 Board Sensor
VCC VCC
GND GND
A A
B B
These connections i have used as markd833 said, How to read it through code, Can anyone tell me exact short snippet, which ill work for my application..
Sensor A,B,Vcc,GND i connected to RS485 A,B,GND,Vcc and RO to D0(RX), DI to D1(TX), RE to D2 , DE to D3.
How to read my sensor data
Those pins were given assuming that this is the board you have:
These pins i identified by blinking LED in each pin , I f i use these variables as name written on board, then only LED blinks at that pins. By seeing this please help me to print my sensor data on UART / Serial monitor
For D2 and D4 , LED didnt bliked.
Digital Pins
D3 - const int LED_PIN = 3;
D5 - const int LED_PIN = 5;
D6 - const int LED_PIN = 6;
D7 - const int LED_PIN = 7;
D8 - const int LED_PIN = 8;
D9 - const int LED_PIN = 9;
D10 - const int LED_PIN = 10;
D11 - const int LED_PIN = 11;
D12 - const int LED_PIN = 12;
D13 - const int LED_PIN = 13;
Analog Pins
A0 - const int LED_PIN = A0 or 14
A1 - const int LED_PIN = A1 or 15
A2 - const int LED_PIN = A2 or 16
A3 - const int LED_PIN = A3 or 17
A4 - const int LED_PIN = A4 or 18
A5 - const int LED_PIN = A5 or 19
D20 - static const uint8_t SDA = PIN_WIRE_SDA; (20u)
D21 - static const uint8_t SCL = PIN_WIRE_SCL; (21u)
Yes, it is the same exact board , i have
use Serial1 instead of SoftwareSerial. so Serial1.begin etc
I've had a quick play with my SAMD21 board that looks exactly like your board. In the IDE I used "Arduino Zero (Native USB Port)" as the device.
Using Library Manager, search for and install the ArduinoModbus library. It will also want to install the ArduinoRS485 library.
Once, installed, load up the example ArduinoModbus -> RTU -> ModbusRTUClientToggle.
That example toggles a coil on and off for device 01. It will use the RX & TX serial pins without any modification. It makes use of the ArduinoRS485 library which uses A4 to drive the DE pin and A5 to drive the RE pin.
From that simple example, you should be able to move forward with your project. Don't forget that the MAX485 board you have is a 5V board and you need to level shift the RO signal before feeding it into the RX pin on your SAMD board.
For debug printing, I had to change the code to use SerialUSB rather than plain Serial.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.