Hello,
I am looking to send a ph sensors data from my uno, to my mega, and then display it on an LCD. I will explain why I can't just attach the uno to the lcd in a sec.
Right now the issue is that for my application, I cannot find a suitable way to send that data from the uno to the mega. I have looked into union implementation and other serial methods, but I can't seem to find anything that fits the application and is suitable.
I have an understanding that in order for the Serial.write() function to work, I need to have either a string, int, or byte to send. I have tried to convert the ph value to an int because it seemed the easiest but the values are getting lost or misread.
I know that the best solution is probably to convert the float to a byte array, however none of the online tutorials have really worked for me and I haven't seen any way to implement them into sending data across the arduinos.
why am i doing all this? Because i made a crappy arduino shield design that didnt have external access to the dig pins, so now i can either solder on jumper connections from the lcd to the uno shield or write the proper code to display the ph without a computer screen. The goal here is to have a working hydroponics system to give my parents by this friday, before i move out for college. So far I have the ph monitoring and flood timing system ready, I am just looking to get the last few kinks out of the way before its ready.
anyways, heres the uno (sender) code
void loop() {
timer.tick();
if (Serial.available() > 0) {
user_bytes_received = Serial.readBytesUntil(13, user_data, sizeof(user_data));
}
if (user_bytes_received) {
parse_cmd(user_data);
user_bytes_received = 0;
memset(user_data, 0, sizeof(user_data));
}
float ph = (pH.read_ph());
ph = ph * 100;
int x = ph;
Serial.write(x);
delay(1000);
}
and heres the mega (receiver) code
#include <LiquidCrystal.h>
const int rs = 9, en = 8, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int inByte = 0;
double ph;
void setup(){
Serial.begin(9600);
Serial1.begin(9600);
lcd.begin(16,2);
lcd.print("pH: ");
lcd.setCursor(4, 0);
}
void loop(){
if(Serial.available()){
inByte = Serial1.read();
ph = inByte;
lcd.print(ph);
lcd.setCursor(4, 0);
}
delay(1000);
}