Browse Source

Added ADS1115 functions

master
Englebert 1 year ago
parent
commit
7c11a7305a
  1. 4
      platformio.ini
  2. BIN
      src/.main.cpp.swp
  3. BIN
      src/.main.h.swp
  4. 54
      src/main.cpp
  5. 43
      src/main.h

4
platformio.ini

@ -12,4 +12,6 @@
platform = espressif32
board = esp32dev
framework = arduino
lib_deps = thingpulse/ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.4.0
lib_deps =
thingpulse/ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.4.0
robtillaart/ADS1X15@^0.3.10

BIN
src/.main.cpp.swp

BIN
src/.main.h.swp

54
src/main.cpp

@ -19,6 +19,7 @@ uint8_t button10 = 0;
// Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire1, -1);
// Initialize the OLED display using Wire library
SSD1306Wire display(0x3C, OLED_SDA, OLED_SCL, GEOMETRY_128_64, I2C_TWO, 700000);
ADS1115 ADS(0x48, &Wire1);
void setup() {
Serial.begin(115200);
@ -40,6 +41,7 @@ void setup() {
i2c_status = true;
}
// Init Display
display.init();
display.setContrast(255);
display.setTextAlignment(TEXT_ALIGN_LEFT);
@ -47,6 +49,18 @@ void setup() {
display.drawString(0, 16, "BigRC v1.0");
display.display();
// Init ADC
if(!ADS.begin(ADS1115_SCL, ADS1115_SDA)) {
display.setFont(ArialMT_Plain_10);
display.drawString(0, 0, "ADS1115 ERROR!");
display.display();
delay(5000);
}
//// ADS.setWireClock(100000);
ADS.setGain(1); // +- 4.096V
ADS.setDataRate(7); // 7 = Fastest
//// Wire.beginTransmission(I2C_DEVICE_MAX_ADDRESS_RANGE - 2);
// Preparing I/O
@ -114,15 +128,15 @@ void setup() {
CPU_1
);
xTaskCreatePinnedToCore(
taskSystemStatus,
"TaskSystemStatus", // Name of the process
8192, // This stack size can be checked & adjusted by reading the Stack Highwater
NULL,
4, // Priority
NULL,
CPU_1
);
// xTaskCreatePinnedToCore(
// taskSystemStatus,
// "TaskSystemStatus", // Name of the process
// 8192, // This stack size can be checked & adjusted by reading the Stack Highwater
// NULL,
// 4, // Priority
// NULL,
// CPU_1
// );
xTaskCreatePinnedToCore(
taskGimbal,
@ -400,20 +414,24 @@ void taskGimbal(void *pvParameters) {
// raw_throttle = analogRead(THROTTLE_PIN);
// throttle_steps = median_throttle(raw_throttle);
// Sampling throttle
throttle_steps = sampling(THROTTLE_POOL);
// throttle_steps = sampling(THROTTLE_POOL);
throttle_steps = ADS.readADC(3);
// raw_yaw = analogRead(YAW_PIN);
// yaw_steps = median_yaw(raw_yaw);
// Sampling yaw
yaw_steps = sampling(YAW_POOL);
// yaw_steps = sampling(YAW_POOL);
yaw_steps = ADS.readADC(2);
// raw_roll = analogRead(ROLL_PIN);
// roll_steps = median_roll(raw_roll);
roll_steps = sampling(ROLL_POOL);
// roll_steps = sampling(ROLL_POOL);
roll_steps = ADS.readADC(1);
// raw_pitch = analogRead(PITCH_PIN);
// $pitch_steps = median_pitch(raw_pitch);
pitch_steps = sampling(PITCH_POOL);
// pitch_steps = sampling(PITCH_POOL);
pitch_steps = ADS.readADC(0);
// profiling_end = micros();
@ -442,7 +460,7 @@ void taskCounter(void *pvParameters) {
for(;;) {
vTaskDelay(1);
if((uint32_t)(millis() - last_update) > 1000) {
if((uint32_t)(millis() - last_update) > 1001) {
counter = counter_raw;
counter_raw = 0;
@ -985,8 +1003,12 @@ void display_info(void) {
float voltage = voltage_steps * VOLTAGE_MULTIPLER;
display.drawString(24, 0, String(voltage) + "V");
display.drawString(24, 16, String(profile_gimbal_rate) + " G Rate");
display.drawString(24, 32, String(i2c_counter) + " I2C Rate");
display.drawString(24, 8, String(profile_gimbal_rate) + " G Rate");
display.drawString(24, 16, String(i2c_counter) + " I2C Rate");
display.drawString(24, 24, "Throttle: " + String(throttle_steps));
display.drawString(24, 32, "Yaw : " + String(yaw_steps));
display.drawString(24, 40, "Roll : " + String(roll_steps));
display.drawString(24, 48, "Pitch : " + String(pitch_steps));
// Toggle Buttons Info
if(toggle_buttons[TOGGLE_A]) {

43
src/main.h

@ -38,6 +38,9 @@
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// ADS1115
#define ADS1115_SDA 16
#define ADS1115_SCL 17
// VERSION
#define VERSION_MAJOR 0
@ -55,6 +58,8 @@
#include "i2c_protocols.h"
#include "SSD1306Wire.h" // legacy include: `#include "SSD1306.h"`
#include "ADS1X15.h"
typedef struct struct_data {
@ -176,27 +181,27 @@ int16_t counter = 0;
uint16_t voltage_steps = 0;
uint16_t current_steps = 0;
uint16_t throttle_steps = 0;
uint16_t yaw_steps = 0;
uint16_t roll_steps = 0;
uint16_t pitch_steps = 0;
uint16_t throttle_val = 0;
uint16_t throttle_val_tmp = 0;
uint16_t yaw_val = 0;
uint16_t yaw_val_tmp = 0;
uint16_t pitch_val = 0;
uint16_t pitch_val_tmp = 0;
uint16_t roll_val = 0;
uint16_t roll_val_tmp = 0;
int16_t yaw_steps = 0;
int16_t roll_steps = 0;
int16_t pitch_steps = 0;
int16_t throttle_val = 0;
int16_t throttle_val_tmp = 0;
int16_t yaw_val = 0;
int16_t yaw_val_tmp = 0;
int16_t pitch_val = 0;
int16_t pitch_val_tmp = 0;
int16_t roll_val = 0;
int16_t roll_val_tmp = 0;
// Active calibration
uint16_t min_throttle = 1000;
uint16_t max_throttle = 1800;
uint16_t min_yaw = 1800;
uint16_t max_yaw = 1000;
uint16_t min_pitch = 1800;
uint16_t max_pitch = 1000;
uint16_t min_roll = 1800;
uint16_t max_roll = 1000;
int16_t min_throttle = 32767;
int16_t max_throttle = 0;
int16_t min_yaw = 32767;
int16_t max_yaw = 0;
int16_t min_pitch = 32767;
int16_t max_pitch = 0;
int16_t min_roll = 32767;
int16_t max_roll = 0;
uint16_t gimbal_rate = 0;

Loading…
Cancel
Save