ThingPulse / esp8266-oled-ssd1306

Driver for the SSD1306 and SH1106 based 128x64, 128x32, 64x48 pixel OLED display running on ESP8266/ESP32
https://thingpulse.com
Other
2k stars 638 forks source link

NodeMCU using ADS1115 and SH1106 #252

Closed LeonPJ closed 4 years ago

LeonPJ commented 5 years ago

When I using ADS1115 to read ADC it can work, but if I connect with SH1106 the ADC value will be worn. Does anybody know what happened? My project was using NoedMCU with ADS1115 to read ZMPT101B this AC sensor and print value on OLED. This is my code

//ADS1115 library

include

include

//SSD1306 library

include "SH1106Wire.h"

//---------------------------------------------------------------------------------------------------------------------------------------------- /set/ //set OLED SH1106Wire display(0x3C, D2, D1);// D2 SDA, D1 SCL // set ADS1115 Adafruit_ADS1115 ads(0x48); / Use this for the 16-bit version / //maybe can use up code to change ads address

float IrmsVrms() { uint32_t RMSPage = millis(); float Iresult = 0.00; float ImaxValue = 0.50;// I max value float IminValue = 4.50;// I min value float Vresult = 0.00; float VmaxValue = 1.00;// V max value float VminValue = 3.30;// V min value uint32_t start_time = millis(); while((millis()-start_time) < 1000) {// measure for 1s float readVValue = (ads.readADC_SingleEnded(0) 0.1875 /1000);// vltage if (readVValue > VmaxValue) { // VmaxValue = readVValue;// record the maximum sensor value }else if (readVValue < VminValue) { VminValue = readVValue;// record the maximum sensor value } } Vresult = (VmaxValue - VminValue); //Serial.println(Vresult); float Vrms = ((Vresult / 2) 0.707 * 172); return Vrms; }

void setup() { Serial.begin(115200); ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV 0.1875mV (default) ads.begin(); pinMode(D5, INPUT);// local control pinMode(D3, OUTPUT);// relay control pinMode(D0, OUTPUT); display.init(); display.flipScreenVertically(); display.setFont(ArialMT_Plain_24);//24 16 10 display.setTextAlignment(TEXT_ALIGN_LEFT); }

void loop() { float VVrms = IrmsVrms(); display.setFont(ArialMT_Plain_24);//24 16 10 display.clear(); // clearing the display display.drawString(0, 0, VVrms); display.display(); display.clear(); // clearing the display }

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.