is it possible to use rs485 directly with a boron or do I need some kind of converter?
You'll need additional hardware that does the voltage and half-duplex conversion, but it's inexpensive.
so i got the converters and have two of them talking between an Arduino and a Boron. I'm now trying to get it to work with the 7in1 soil sensor, but I am having problems. The command byte is been sent but the sensor is not responding. I am almost sure that the command byte is correct as it is from the datasheet so I think that the problem is with the communication.
this is my code:
#include <Particle.h>
#define SSerialTxControl 2 //when this pin is HIGH the transmitter is on
#define SSerialRxControl 3 //when this pin is HIGH the reserve is off
#define RS485Transmit HIGH
#define RS485Receive LOW
void setup() {
pinMode(SSerialTxControl, OUTPUT);
pinMode(SSerialRxControl, OUTPUT);
digitalWrite(SSerialTxControl, RS485Receive);
Serial1.begin(9600);
}
void loop(){
const byte queryData[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x04, 0x44, 0x09}; //the command byte
byte receivedData[19];
digitalWrite(SSerialTxControl, RS485Transmit);//enabling the transmitter
digitalWrite(SSerialRxControl, RS485Transmit);//disabling the reserve
Serial1.write(queryData, sizeof(queryData));
delay(100);
digitalWrite(SSerialTxControl, RS485Receive); // Disabling the transmitter
digitalWrite(SSerialRxControl, RS485Receive);//enabling the reserve
delay(2000);
Particle.publish("1", String(Serial1.available()));//checking if there is a response
if (Serial1.available() >= sizeof(receivedData)) {
digitalWrite(SSerialTxControl, RS485Receive);
digitalWrite(SSerialRxControl, RS485Receive);
for (int i = 0; i < sizeof(receivedData); i++){
receivedData[i] = Serial1.read();
}
// Parse and print the received data in decimal format
unsigned int soilHumidity = (receivedData[3] << 8) | receivedData[4];
unsigned int soilTemperature = (receivedData[5] << 8) | receivedData[6];
unsigned int soilConductivity = (receivedData[7] << 8) | receivedData[8];
unsigned int soilPH = (receivedData[9] << 8) | receivedData[10];
unsigned int nitrogen = (receivedData[11] << 8) | receivedData[12];
unsigned int phosphorus = (receivedData[13] << 8) | receivedData[14];
unsigned int potassium = (receivedData[15] << 8) | receivedData[16];
char str[255];
sprintf(str, "%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f", soilHumidity, soilTemperature, soilConductivity, soilPH, nitrogen, phosphorus, potassium);
Particle.publish("2", str);
}
delay(1000);
}
Please let me know what I need to change to get this working.