I am building an ultrasonic wing instrument for my boat. The interface to the instrument is RS485. I can access and interact with the wind instrument with an RS485 USB dongle and my PC. So far so good.
I would now like to poll the same device with a Teensy 4.1. I have a Sparkfun BOB-10125 breakout board that is 3.3V powered. I'm using the Arduino 2.3.2 IDE, and the Teensyduino 1.59.
Downloaded and installed the ModbusArduino Library, and the Arduino RS485 library. Looked at the sample code for the Temperature Sesnsor. My requirements are almost identical, so I started with that.. I read through a bunch of posts on this forum but I'm still stumped on how to get the Serial1 hardware port to work, specifically I'm not sure where to connect the RTS bin on the BOB.. I tried pin 2 on the teensy, but that didn't work..
I can see the transmit LED pulse on the BOB, but in the serial monitor I keep getting timeout errors..
Did I maybe get my RX/TX lines crossed? If anyone has the BOB-10125 working with their Teensy 4.1 any help would be appreciated..
I would now like to poll the same device with a Teensy 4.1. I have a Sparkfun BOB-10125 breakout board that is 3.3V powered. I'm using the Arduino 2.3.2 IDE, and the Teensyduino 1.59.
Downloaded and installed the ModbusArduino Library, and the Arduino RS485 library. Looked at the sample code for the Temperature Sesnsor. My requirements are almost identical, so I started with that.. I read through a bunch of posts on this forum but I'm still stumped on how to get the Serial1 hardware port to work, specifically I'm not sure where to connect the RTS bin on the BOB.. I tried pin 2 on the teensy, but that didn't work..
C++:
/*
Modbus RTU Wind Sensor Sensor
This sketch shows you how to interact with a Modbus RTU wind speed and direction sensor.
It reads the speed and direction va;ues continuously and outputs them to the
serial monitor.
Based on teh sample temperature provided by
by Riccardo Rizzo
*/
#include <ArduinoRS485.h>
#include <ArduinoModbus.h>
float windspeedms;
float winddirction;
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("Modbus Wind Sensor");
Serial1.transmitterEnable(2);
// start the Modbus RTU client
if (!ModbusRTUClient.begin(9600)) {
Serial.println("Failed to start Modbus RTU Client!");
while (1);
}
Serial1.transmitterEnable(2);
}
void loop() {
// send a Holding registers read request to (slave) id 1, for 2 registers
if (!ModbusRTUClient.requestFrom(1, HOLDING_REGISTERS, 0x00, 2)) {
Serial.print("failed to read registers! ");
Serial.println(ModbusRTUClient.lastError());
} else {
// If the request succeeds, the sensor sends the readings, that are
// stored in the holding registers. The read() method can be used to
// get the raw temperature and the humidity values.
short rawwindspeedms = ModbusRTUClient.read();
short rawwinddirction = ModbusRTUClient.read();
// To get the temperature in Celsius and the humidity reading as
// a percentage, divide the raw value by 10.0.
windspeedms = rawwindspeedms / 100.0;
winddirction = rawwinddirction;
Serial.println(windspeedms);
Serial.println(winddirction);
}
delay(50);
}
I can see the transmit LED pulse on the BOB, but in the serial monitor I keep getting timeout errors..
Code:
Modbus Wind Sensor
failed to read registers! Connection timed out
failed to read registers! Connection timed out
failed to read registers! Connection timed out
Did I maybe get my RX/TX lines crossed? If anyone has the BOB-10125 working with their Teensy 4.1 any help would be appreciated..