this value on lcd is ok lcd.print(buf);
but when I try to use Serial.println(buf); I got wrong value
#include <LiquidCrystal.h> // include Arduino LCD library
// LCD module connections (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
void setup(void) {
Serial.begin(115200);
lcd.begin(16, 2); // set up the LCD's number of columns and rows
lcd.setCursor(0, 0);
lcd.print("RMS Voltage:");
analogReference(INTERNAL); // set ADC positive reference voltage to 1.1V (internal)
}
// get maximum reading value
uint16_t get_max() {
uint16_t max_v = 0;
for(uint8_t i = 0; i < 100; i++) {
uint16_t r = analogRead(A3); // read from analog channel 3 (A3)
if(max_v < r) max_v = r;
delayMicroseconds(200);
}
return max_v;
}
// main loop
void loop() {
char buf[10];
// get amplitude (maximum - or peak value)
uint32_t v = get_max();
// get actual voltage (ADC voltage reference = 1.1V)
v = v * 1116/1023;
// calculate the RMS value ( = peak/√2 )
v /= sqrt(2);
sprintf(buf, "%03u Volts", v);
lcd.setCursor(0, 1);
lcd.print(buf);
Serial.println(buf);
delay(500);
}
How did you change the rest of the code? Support for floats was cut out of sprintf for most of the Arduinos because it took up too much space. So the common remedy is to use dtostrf to turn the float to a char array and then use sprintf if you need to add more to that.
I mean it hasn't worked on the normal Arduino as long as I've been around them. I don't know about some of the fancy new ones, but for things like UNO and Mega and Nano and such, it's never worked as far as I know.
There is a way to enable it, but it takes up way more program space than it's worth if I understand right. Here's an older thread that claims to have it, but I haven't followed the link.