Error message trying to send a value through bluetooth (ardunio)

jayanthd

Joined Jul 4, 2015
945
Try this

C:
void loop() {
 if(Serial.available() > 0)
{
 val=Serial.read();
 lcd.setCursor (i,0);
 lcd.print(val);
if(++i >= 16)i = 0; 
}
 

be80be

Joined Jul 5, 2008
2,395
That's because I don't think Jay understands you did the math on the sending side when you add 1.0 that set's the size
Serial.print sends it out one byte at a time. If it's 6 byte it send them all.
Now what you need to do is send the number out raw and on the receiving side do the math
print() will return the number of bytes written, though reading that number is optional
 

jayanthd

Joined Jul 4, 2015
945
That's because I don't think Jay understands you did the math on the sending side when you add 1.0 that set's the size
Serial.print sends it out one byte at a time. If it's 6 byte it send them all.
Now what you need to do is send the number out raw and on the receiving side do the math
"123.4578" is sent one character at a time. It has 8 characters. So, a buffer of 9 will do. Read is using serial interrupt and send it to lcd.print().
 

be80be

Joined Jul 5, 2008
2,395
It you read the core for print it dose stuff for you that why it's so easy to use.
when he put 1023.0 that set's the size to float.
But if you declare you get errors which is what was happening.
But it would be easier if he did the math on the LCD side and send out the value raw
The adc pin reads 1023 so you send say 512 thats 2.5 volts
you print that to the LCD
 

be80be

Joined Jul 5, 2008
2,395
This should do as planned
Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
  Serial.begin(38400);
  lcd.begin(16, 2);
}
void loop()
{
   if(Serial.available() > 0)
   {
   lcd.clear();
   float x = Serial.read();
   float y = x * (5.0/1023.0);
   lcd.setCursor(0, 1);
   lcd.print(y);
   delay(2000);
   }
}
And the send code
Code:
int val;
#define button 3
void setup() {
  Serial.begin(38400);
  pinMode(button , INPUT);
}
void loop() {
    val = digitalRead(button);
    if (val == HIGH)
  {
    int sensor = analogRead(A0);
    int voltage0 = sensor;
    Serial.println(voltage0);
    delay(500);
  }
}
 
Top