Compass to lcd
i have hmc5883l compass, wired , working on uno. (with sketch hmc5883l loaded) have sainsmart lcd display wired , working. (with sketch lcd loaded)
how go getting lcd display values can see on serial monitor?
this have far...
it displays compass ver 1 on 1st line ,
heading= on second line.
thanks!
how go getting lcd display values can see on serial monitor?
this have far...
code: [select]
#include <liquidcrystal.h>
liquidcrystal lcd(8, 9, 4, 5, 6, 7);
#include <wire.h>
#include <hmc5883l.h>
hmc5883l compass;
void setup(){
serial.begin(9600);
wire.begin();
compass = hmc5883l(); //new instance of hmc5883l library
setuphmc5883l(); //setup hmc5883l
lcd.begin(16, 2);
lcd.setcursor(0,0);
lcd.print("compass ver 1");
lcd.setcursor(0,1);
lcd.print("heading=");
}
void loop()
{
lcd.setcursor(1,10); // move cursor second line "1" , 10 spaces over
{
float heading = getheading();
serial.println(heading);
delay(1000); //only here slow down serial print
}
}
void setuphmc5883l(){
int error;
error = compass.setscale(1.3);
if(error != 0) serial.println(compass.geterrortext(error));
error = compass.setmeasurementmode(measurement_continuous);
if(error != 0) serial.println(compass.geterrortext(error));
}
float getheading(){
magnetometerscaled scaled = compass.readscaledaxis();
float heading = atan2(scaled.yaxis, scaled.xaxis);
if(heading < 0) heading += 2*pi;
if(heading > 2*pi) heading -= 2*pi;
return heading * rad_to_deg;
}
it displays compass ver 1 on 1st line ,
heading= on second line.
thanks!
i surprised question.
the program outputs lcd , position cursor ready output heading
what problem ?
the program outputs lcd , position cursor ready output heading
code: [select]
lcd.setcursor(1, 10); // move cursor second line "1" , 10 spaces over
but never output heading lcd.what problem ?
Arduino Forum > Using Arduino > Programming Questions > Compass to lcd
arduino
Comments
Post a Comment