LCD 16*2 doesn't work when code joined with ACS712 sensor
hello!
i'm working project telemetry street lamp. using acs712 current sensor(ac current) , rectifier voltage sensor (and lcd i2c interface), when test each code, work when joined current sensor code , lcd code. lcd not show character.
acs712 code
lcd code
final code
every advice may helps problem here
thanks
i'm working project telemetry street lamp. using acs712 current sensor(ac current) , rectifier voltage sensor (and lcd i2c interface), when test each code, work when joined current sensor code , lcd code. lcd not show character.
acs712 code
code: [select]
#include <filters.h>
float testfrequency = 60; // test signal frequency (hz)
float windowlength = 20.0/testfrequency; // how long average signal, statistist
int sensorvalue = 0;
float intercept = -0.1129; // adjusted based on calibration testing
float slope = 0.0405; // adjusted based on calibration testing
float current_amps; // estimated actual current in amps
unsigned long printperiod = 1000; // in milliseconds
// track time in milliseconds since last reading
unsigned long previousmillis = 0;
void setup() {
serial.begin( 57600 ); // start serial port
}
void loop() {
runningstatistics inputstats; // create statistics @ raw test signal
inputstats.setwindowsecs( windowlength );
while( true ) {
sensorvalue = analogread(a0); // read analog in value:
inputstats.input(sensorvalue); // log stats function
if((unsigned long)(millis() - previousmillis) >= printperiod) {
previousmillis = millis(); // update time
// display current values screen
serial.print( "\n" );
// output sigma or variation values associated inputvalue itsel
serial.print( "\tsigma: " ); serial.print( inputstats.sigma() );
// convert signal sigma value current in amps
current_amps = intercept + slope * inputstats.sigma();
serial.print( "\tamps: " ); serial.print( current_amps );
}
}
}
lcd code
code: [select]
/* http://www.electronoobs.com */
/*-----( inport library )-----*/
#include <wire.h>
#include <liquidcrystal_i2c.h>
//i2c pins
liquidcrystal_i2c lcd(0x3f, 2, 1, 0, 4, 5, 6, 7, 3, positive); //
int volt=0;
int amp=0;
void setup()
{
serial.begin(9600);
//we define our lcd 16 columns , 2 rows
lcd.begin(16,2);
lcd.backlight();//power on light
//lcd.backlight(); power off light
}
void loop()
{
//write text:
lcd.setcursor(0,0); //we start writing first row first column
lcd.print("tegangan: "); //16 characters poer line
lcd.setcursor(0,1);
lcd.print("arus: ");
delay(1000);
}
final code
code: [select]
#include <filters.h>
#include <wire.h>
#include <liquidcrystal_i2c.h>
//i2c pins
liquidcrystal_i2c lcd(0x3f, 2, 1, 0, 4, 5, 6, 7, 3, positive); //
int volt = 0;
int amp = 0;
float testfrequency = 60; // test signal frequency (hz)
float windowlength = 20.0 / testfrequency; // how long average signal, statistist
int sensorvalue = 0;
float intercept = -0.1129; // adjusted based on calibration testing
float slope = 0.0405; // adjusted based on calibration testing
float current_amps; // estimated actual current in amps
unsigned long printperiod = 1000; // in milliseconds
// track time in milliseconds since last reading
unsigned long previousmillis = 0;
void setup() {
serial.begin( 9600 ); // start serial port
lcd.begin(16, 2);
lcd.backlight();
}
void loop() {
runningstatistics inputstats; // create statistics @ raw test signal
inputstats.setwindowsecs( windowlength );
while ( true ) {
sensorvalue = analogread(a0); // read analog in value:
inputstats.input(sensorvalue); // log stats function
if ((unsigned long)(millis() - previousmillis) >= printperiod) {
previousmillis = millis(); // update time
// display current values screen
serial.print( "\n" );
// output sigma or variation values associated inputvalue itsel
serial.print( "\tsigma: " ); serial.print( inputstats.sigma() );
// convert signal sigma value current in amps
current_amps = intercept + slope * inputstats.sigma();
serial.print( "\tamps: " ); serial.print( current_amps );
}
}
lcd.setcursor(0, 0); //we start writing first row first column
lcd.print("tegangan: "); //16 characters poer line
lcd.setcursor(0, 1);
lcd.print("arus: "); lcd.print(current_amps, 5);
}
every advice may helps problem here
thanks
the problem in main loop have while( true ) construct lcd code never executed. try commenting out while ( true ) { statement , corresponding closing '}' , see if further.
Arduino Forum > Using Arduino > Displays > LCD 16*2 doesn't work when code joined with ACS712 sensor
arduino
Comments
Post a Comment