I have build wind sensor project based on this tutorial:
It works fine on Uno R3 but when I tried to move it to Nano Every, the wind reading is stuck on 7,72 m/s and sensor doesn't react for wind change. The second readin, direction is working correct.
I have read that Nano Every is not supporting Software Serial on baud 4800 and I would ask you for help if this hardware and software which I have can be converted to use hardware serial?
If it's possible, please help me what changes do I need to make on connection and in the code.
Here is the code from link which I use in my project.
#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
#define RE 8
#define DE 7
const byte anemometer[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x02, 0xC4, 0x0B};
byte values[9];
SoftwareSerial mod(2, 3);
void setup()
{
Serial.begin(9600);
lcd.init();
lcd.backlight();
mod.begin(4800);
pinMode(RE, OUTPUT);
pinMode(DE, OUTPUT);
lcd.setCursor(2, 0);
lcd.print("Wind Speed");
lcd.setCursor(2, 1);
lcd.print("Measurement");
delay(3000);
}
void loop()
{
// Transmit the request to the sensor
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(10);
mod.write(anemometer, sizeof(anemometer));
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
delay(10);
// Wait until we have the expected number of bytes or timeout
unsigned long startTime = millis();
while (mod.available() < 9 && millis() - startTime < 1000)
{
delay(1);
}
if (mod.available() >= 9)
{
// Read the response
byte index = 0;
while (mod.available() && index < 9)
{
values[index] = mod.read();
Serial.print(values[index], HEX);
Serial.print(" ");
index++;
}
Serial.println();
// Parse the Wind Speed value
int Wind_Speed_Int = int(values[3] << 8 | values[4]);
float Wind_Speed_m_s = Wind_Speed_Int / 100.0;
float Wind_Speed_kph = Wind_Speed_m_s * 3.6; // Conversion to km/h
Serial.print("Wind Speed: ");
Serial.print(Wind_Speed_kph);
Serial.println(" km/h");
// Parse the Wind Direction value
int Wind_Direction = int(values[5] << 8 | values[6]);
Serial.print("Wind Direction: ");
Serial.print(Wind_Direction);
Serial.println(" degrees");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Speed:");
lcd.print(Wind_Speed_kph);
lcd.print(" kph");
lcd.setCursor(0, 1);
lcd.print("Dir:");
lcd.print(Wind_Direction);
lcd.print(" deg.");
delay(1000);
}
else
{
Serial.println("Sensor timeout or incomplete frame");
}
}
much more info would be required to help you. Be assured, I have done this, and run 4 Serial as a test.
Start by posting any error/warning messages, with verbose enabled for both compile and upload in preferences. IF you can't get that far, then take a single image of the board config in the IDE. Should look something like:
Post the code you are trying to use on the Nano Every.
What connections have you made from the Nano Every to your MAX485 breakout board?
Can you upload a photo of a hand drawn schematic showing the connections.
Just to clarify, you are still trying to use a software serial port even though the Nano Every has 3 hardware serial ports?
Clarification #2 - It looks like your 12V supply is going to the Vin pin on the Nano Every and the 5V from the 7805 regulator is going to the 5V pin on the Nano Every. Is that correct?
If it is, I'm pretty sure that's not a good idea as the Nano Every will be taking the 12V and using its on-board regulator to generate 5V on that pin too.
I wonder what kind of serial communication problem could cause that output.
You make request for both registers at the same time and transmission has to be correct, otherwise slave would respond with CRC error.
So the question is how can you get invalid response where one address is "stuck" at 0xD7 and the other one gives correct output and changes correctly? Very weird behavior for baudrate problem...
If you can help me with wiring and code I would like to move this project from software serial to hardware serial but I don't know how to manage it.
I can remove 5V from 7805 to 5V on Nano Every if this is bad idea.
When I blow with small USB fan on the sensor, the direction is presented on LCD and in Serial Monitor. and changes when I rotate the sensor.
The Wind Speed is stuck at 7.72
Now seems to be working. Like on Uno R3, from my testing fan it was around 1 m/s and direction is 90 deg from N symbol on sensor body so it also look like ok. Measurements are changing when I move the fan.
It's obvious, because what you read is 4th and 5th byte for speed (0, 75) and 6th and 7th for direction (0, 5A).
Previously you had CRC from previous reading in buffer and everything was shifted by two bytes.
So your wind direction reading was actually wind speed (without conversion factors).