added dynamic display (full buffer) + DAC + ADC
This commit is contained in:
@@ -14,4 +14,4 @@ board = heltec_wifi_lora_32_V2
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
lib_ldf_mode = deep+
|
||||
lib_deps =
|
||||
lib_deps = adafruit/Adafruit ADS1X15@^2.2.0
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "board.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
#include <Wire.h> //include Wire.h library
|
||||
|
||||
void VextOn(void)
|
||||
{
|
||||
//Heltec.begin(true,false,true);
|
||||
@@ -16,3 +18,46 @@ void initBoard(void)
|
||||
VextOn();
|
||||
Serial.println("OK");
|
||||
}
|
||||
|
||||
void scanI2C(void)
|
||||
{
|
||||
byte error, address; //variable for error and I2C address
|
||||
int nDevices;
|
||||
|
||||
Serial.println("Scanning...");
|
||||
|
||||
nDevices = 0;
|
||||
for (address = 1; address < 127; address++)
|
||||
{
|
||||
// The i2c_scanner uses the return value of
|
||||
// the Write.endTransmisstion to see if
|
||||
// a device did acknowledge to the address.
|
||||
Wire.beginTransmission(address);
|
||||
error = Wire.endTransmission();
|
||||
|
||||
if (error == 0)
|
||||
{
|
||||
Serial.print("I2C device found at address 0x");
|
||||
if (address < 16)
|
||||
Serial.print("0");
|
||||
Serial.print(address, HEX);
|
||||
Serial.println(" !");
|
||||
nDevices++;
|
||||
}
|
||||
else if (error == 4)
|
||||
{
|
||||
Serial.print("Unknown error at address 0x");
|
||||
if (address < 16)
|
||||
Serial.print("0");
|
||||
Serial.println(address, HEX);
|
||||
}
|
||||
}
|
||||
if (nDevices == 0)
|
||||
{
|
||||
Serial.println("No I2C devices found\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("done\n");
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
void initBoard(void);
|
||||
void scanI2C(void);
|
||||
|
||||
#define HAS_DISPLAY
|
||||
#define HAS_SSD1322
|
||||
//#define HAS_SSD1306
|
||||
|
||||
|
||||
#define OLED_CS 14
|
||||
#define OLED_DC 17
|
||||
#define OLED_RST 4
|
||||
#define OLED_RST 23
|
||||
#define OLED_MOSI 27
|
||||
#define OLED_SCK 5
|
||||
|
||||
#define ADC_SDA 4
|
||||
#define ADC_SCL 15
|
||||
|
||||
#define DAC1_OUT 26
|
||||
|
||||
#define BUTTON1 21
|
||||
#define BUTTON2 12
|
||||
#define BUTTON3 13
|
||||
#define BUTTON4 16
|
||||
@@ -12,13 +12,11 @@ c_onScreenButton wifiState("Wifi", 9, LocRight, &getWifiState);
|
||||
|
||||
std::vector<c_onScreenButton> MainScreen;
|
||||
|
||||
#ifdef HAS_SSD1322
|
||||
|
||||
#define FONT8 u8g2_font_helvR08_tf
|
||||
#define FONT16 u8g2_font_7x14_tf
|
||||
#define FONT24 u8g2_font_freedoomr25_tn //u8g2_font_logisoso24_tf
|
||||
|
||||
U8G2_SSD1322_NHD_256X64_2_4W_HW_SPI display(U8G2_R0, OLED_CS, OLED_DC, OLED_RST);
|
||||
U8G2_SSD1322_NHD_256X64_F_4W_HW_SPI display(U8G2_R0, OLED_CS, OLED_DC, OLED_RST);
|
||||
|
||||
void initMainScreenButtons(void)
|
||||
{
|
||||
@@ -117,6 +115,10 @@ void c_onScreenButton::drawButton()
|
||||
//hide button
|
||||
return;
|
||||
}
|
||||
display.setDrawColor(0);
|
||||
display.drawBox(_xpos, _ypos, _width, _height);
|
||||
display.setDrawColor(1);
|
||||
|
||||
|
||||
if (getState())
|
||||
{
|
||||
@@ -134,7 +136,7 @@ void c_onScreenButton::drawButton()
|
||||
display.setDrawColor(1);
|
||||
}
|
||||
|
||||
String showValue(String designator, double value, String unit)
|
||||
String showValue(String designator, float value, String unit)
|
||||
{
|
||||
String text;
|
||||
text.clear();
|
||||
@@ -162,11 +164,6 @@ void drawProgressBar(uint16_t x, uint16_t y, uint16_t width, uint16_t height, ui
|
||||
|
||||
void drawMeasurementValues()
|
||||
{
|
||||
// display.setFont(FONT16);
|
||||
// display.drawStr(0, 12, showValue("m:", getMin(), "").c_str());
|
||||
// display.drawStr(80, 12, showValue("r:", getRms(), "").c_str());
|
||||
// display.drawStr(160, 12, showValue("m:", getMax(), "").c_str());
|
||||
|
||||
drawDashedHLine(0,12,220);
|
||||
drawDashedVLine(40,12,33);
|
||||
display.setFont(FONT8);
|
||||
@@ -175,7 +172,9 @@ void drawMeasurementValues()
|
||||
|
||||
display.setFont(FONT24);
|
||||
|
||||
display.drawStr(60, 45, showValue("", getValue(), "").c_str());
|
||||
//display.drawStr(60, 45, String(getValue()).c_str());
|
||||
display.setCursor(60,45);
|
||||
display.printf("%4.2f",getValue());
|
||||
uint16_t stringwidth = display.getStrWidth(showValue("", getValue(), "").c_str());
|
||||
display.setFont(u8g2_font_8x13_t_symbols);
|
||||
display.drawUTF8(60+stringwidth+3 , 43, "mΩ");
|
||||
@@ -213,12 +212,13 @@ void handleDisplay()
|
||||
uint64_t currentmillis = millis();
|
||||
if (currentmillis - lastDisplayTime > SCREENREFRESH)
|
||||
{
|
||||
do
|
||||
{
|
||||
display.clearBuffer();
|
||||
|
||||
// do
|
||||
// {
|
||||
drawMainScreen();
|
||||
} while (display.nextPage());
|
||||
// } while (display.nextPage());
|
||||
display.sendBuffer();
|
||||
lastDisplayTime = millis();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -25,5 +25,5 @@ void loop()
|
||||
handleLeds();
|
||||
handleMeasure();
|
||||
|
||||
Serial.printf("T=%4.2f\n", (double)(micros() - looptime)/1000);
|
||||
Serial.printf("T=%4.2fms\n", (double)(micros() - looptime)/1000);
|
||||
}
|
||||
@@ -1,12 +1,78 @@
|
||||
#include "measure.h"
|
||||
|
||||
Adafruit_ADS1015 ads; /* Use this for the 12-bit version */
|
||||
|
||||
uint64_t lastMeasurement = 0;
|
||||
uint64_t lastDacWrite = 0;
|
||||
bool dacDir = false;
|
||||
int deg = 0;
|
||||
|
||||
float ADCvolts = 0;
|
||||
|
||||
void handleADC(void)
|
||||
{
|
||||
uint64_t currentmillis = millis();
|
||||
if (currentmillis - lastMeasurement > MEASUREMENTINTERVAL)
|
||||
{
|
||||
ADCvolts = ads.computeVolts(ads.readADC_SingleEnded(0));
|
||||
|
||||
lastMeasurement = currentmillis;
|
||||
}
|
||||
}
|
||||
|
||||
void handleDAC(void)
|
||||
{
|
||||
uint64_t currentmillis = millis();
|
||||
if (currentmillis - lastDacWrite > DACINTERVAL)
|
||||
{
|
||||
if (deg >= 254)
|
||||
{
|
||||
dacDir = false;
|
||||
deg = 254;
|
||||
}
|
||||
if (deg <= 0)
|
||||
{
|
||||
dacDir = true;
|
||||
deg = 0;
|
||||
}
|
||||
|
||||
dacWrite(DAC1_OUT, deg);
|
||||
|
||||
if (dacDir)
|
||||
{
|
||||
deg += DACSTEP;
|
||||
}
|
||||
else
|
||||
{
|
||||
deg -= DACSTEP;
|
||||
}
|
||||
|
||||
|
||||
lastDacWrite = currentmillis;
|
||||
}
|
||||
}
|
||||
|
||||
void initMeasure(void)
|
||||
{
|
||||
|
||||
Serial.print("init measurements:ADC=");
|
||||
if (!ads.begin())
|
||||
{
|
||||
Serial.println("Failed to initialize ADS.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("OK");
|
||||
}
|
||||
lastMeasurement = millis();
|
||||
lastDacWrite = millis();
|
||||
|
||||
pinMode(BUTTON3, INPUT_PULLUP);
|
||||
}
|
||||
|
||||
void handleMeasure(void)
|
||||
{
|
||||
|
||||
handleADC();
|
||||
handleDAC();
|
||||
}
|
||||
|
||||
measureMode getMeasureMode(void)
|
||||
@@ -34,9 +100,10 @@ uint8_t getBar(void)
|
||||
return 68;
|
||||
}
|
||||
|
||||
double getValue(void)
|
||||
float getValue(void)
|
||||
{
|
||||
return 144.8;
|
||||
Serial.printf("ADCvolts:%4.2fV\n",ADCvolts);
|
||||
return ADCvolts;
|
||||
}
|
||||
|
||||
bool getErrorState(void)
|
||||
@@ -46,7 +113,7 @@ bool getErrorState(void)
|
||||
|
||||
bool getOkState(void)
|
||||
{
|
||||
return true;
|
||||
return digitalRead(BUTTON3);
|
||||
}
|
||||
|
||||
bool getOpenState(void)
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "board.h"
|
||||
#include <Adafruit_ADS1X15.h>
|
||||
|
||||
#define MEASUREMENTINTERVAL 10 //ms
|
||||
#define DACINTERVAL 10 //ms
|
||||
#define DACSTEP 8 //ticks
|
||||
|
||||
enum measureMode
|
||||
{
|
||||
@@ -23,7 +29,7 @@ double getMin( void);
|
||||
double getMax(void);
|
||||
double getRms(void);
|
||||
uint8_t getBar(void);
|
||||
double getValue(void);
|
||||
float getValue(void);
|
||||
|
||||
bool getErrorState(void);
|
||||
bool getOkState(void);
|
||||
|
||||
Reference in New Issue
Block a user