hello.
i made a ohm meter in my ardino uno. this is the code( i don't need LCD any more):
#include <LiquidCrystal_I2C.h>
#include<SoftwareSerial.h>
SoftwareSerial SUART(5, 6);//SRX = 5, STX = 6
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define CH0 12
#define CH1 11
#define CH2 10
#define CH3 9
#define CH4 8
// variables
byte ch_number;
uint32_t res;
const uint32_t res_table[5] = {100, 1000, 10000, 100000, 2000000};
char _buffer[11];
void setup(void) {
SUART.begin(9600);
lcd.init();
// turn on the backlight
lcd.backlight();
pinMode(CH0, OUTPUT);
pinMode(CH1, OUTPUT);
pinMode(CH2, OUTPUT);
pinMode(CH3, OUTPUT);
pinMode(CH4, OUTPUT);
ch_number = 4;
ch_select(ch_number);
Serial.begin(9600);
}
// main loop
void loop() {
uint16_t volt_image = analogRead(A1) + 1;
if(volt_image >= 550 && ch_number < 4) {
ch_number++;
ch_select(ch_number);
delay(50);
return;
}
if(volt_image <= 90 && ch_number > 0) {
ch_number--;
ch_select(ch_number);
delay(50);
return;
}
if(volt_image < 900) {
float value = (float)volt_image*res/(1023 - volt_image);
if(value < 1000.0)
sprintf(_buffer, "%03u.%1u", (uint16_t)value, (uint16_t)(value*10)%10);
else if(value < 10000.0)
sprintf(_buffer, "%1u%03u", (uint16_t)(value/1000), (uint16_t)value%1000);
else if(value < 100000.0)
sprintf(_buffer, "%02u%02u0", (uint16_t)(value/1000), (uint16_t)(value/10)%100);
else if(value < 1000000.0)
sprintf(_buffer, "%03u%1u00", (uint16_t)(value/1000), (uint16_t)(value/100)%10);
else
sprintf(_buffer, "%1u%03u000", (uint16_t)(value/1000000), (uint16_t)(value/1000)%1000);
}
else
sprintf(_buffer, "Over Load ");
lcd.setCursor(0, 1); // move cursor to position (0, 1)
lcd.print(_buffer);
Serial.println(_buffer);
SUART.println(_buffer);
delay(500); // wait some time
}
void ch_select(byte n) {
switch(n) {
case 0:
digitalWrite(CH0, LOW);
digitalWrite(CH1, HIGH);
digitalWrite(CH2, HIGH);
digitalWrite(CH3, HIGH);
digitalWrite(CH4, HIGH);
break;
case 1:
digitalWrite(CH0, HIGH);
digitalWrite(CH1, LOW);
digitalWrite(CH2, HIGH);
digitalWrite(CH3, HIGH);
digitalWrite(CH4, HIGH);
break;
case 2:
digitalWrite(CH0, HIGH);
digitalWrite(CH1, HIGH);
digitalWrite(CH2, LOW);
digitalWrite(CH3, HIGH);
digitalWrite(CH4, HIGH);
break;
case 3:
digitalWrite(CH0, HIGH);
digitalWrite(CH1, HIGH);
digitalWrite(CH2, HIGH);
digitalWrite(CH3, LOW);
digitalWrite(CH4, HIGH);
break;
case 4:
digitalWrite(CH0, HIGH);
digitalWrite(CH1, HIGH);
digitalWrite(CH2, HIGH);
digitalWrite(CH3, HIGH);
digitalWrite(CH4, LOW);
}
res = res_table[n];
}
i want to make a plot for the changes of resistance in a web page.
i use softwareserial to transfer the result, to esp8266.
my problem is here: i can't use the input as value for the html plot because it is not string.
when i convert it to string, it writes for example (5167) in ( 5 after some second 1 and 6 and 7 ) so my plot shows 5 then 1 then 6 and 7 ) .in my serial monitor it is same. but when i use void loop for myserial.read
void loop(){
byte n = SUART.available();
if (n != 0)
{
char y = SUART.read();
Serial.print(y);
}
}
all things is right in my serial Monitor , but i can't use it in server.on request:
server.on("/resistance ", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/plain", string().c_str() );
});
.
also i can't run my ohm meter in esp8266 nude. because i need aref pin.
please help me what can i do.