Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
8e476e8
Update custom motd module
SeanChangX Jan 9, 2024
84d4ceb
Fix motd_setup.sh bug
SeanChangX Jan 9, 2024
c072e95
Add autostart config
SeanChangX Jan 25, 2024
7be5e8c
Change conky_setup.sh behavior
SeanChangX Jan 25, 2024
66878f8
Update user_setup.sh
SeanChangX Jan 25, 2024
5b676c1
Add .bash_aliases to default user
SeanChangX Jan 29, 2024
92e87a9
Fix script format
SeanChangX Jan 29, 2024
6894b9d
Fix tab-space convertion
SeanChangX Jan 29, 2024
575d803
Fix tab-space format problem
SeanChangX Jan 29, 2024
fa17c5d
Fix "if-fi" bug
SeanChangX Jan 29, 2024
0e4b010
Fix fi bug again #_#
SeanChangX Jan 29, 2024
65c9b18
Add Non-root part exit
SeanChangX Jan 29, 2024
3fb2bec
Change env_setup.sh
SeanChangX Jan 29, 2024
82a1ba6
Add folder remove option
SeanChangX Jan 29, 2024
0c59fb4
Update .bash_aliases
SeanChangX Jan 31, 2024
13e220a
Change proper format of banner
SeanChangX Jan 31, 2024
30635fc
Update pre-installation script
SeanChangX Feb 21, 2024
5e805d2
Add rotate screen option
SeanChangX Feb 22, 2024
452de21
Add firefox user preference
SeanChangX Feb 22, 2024
58ee186
Change conky_setup.sh running dir
SeanChangX Feb 22, 2024
2faecb8
Change 00-pre-installation.sh firefox pref path
SeanChangX Feb 22, 2024
e0427f1
Update voltage conky display function
SeanChangX Mar 3, 2024
8ab815d
Update ESP32 code - Battery_watchdog
SeanChangX Mar 12, 2024
d839779
Update battery watchdog script
SeanChangX Mar 15, 2024
a2e6029
Merge branch 'dev' of github.com:SeanChangX/DIT-Scripts into dev
SeanChangX Mar 15, 2024
2fdf9b0
Add udev rules folder
SeanChangX Mar 17, 2024
61b32d1
Optimize battery_watchdog sounds feeling
SeanChangX Mar 23, 2024
b24d4e0
Update battery_watchdog performance
SeanChangX Mar 23, 2024
029e9fd
Tidy files & Fix some exec path bug
SeanChangX Mar 24, 2024
8c21050
Update udev rules
SeanChangX Mar 24, 2024
07061cf
Update DIT-2024-12 STM SN number
SeanChangX Mar 25, 2024
e556f3a
Update eurobot2024map web
SeanChangX Apr 14, 2024
69cb435
Add battery display func in web ui
SeanChangX Apr 15, 2024
c7e04bf
Add score display func
SeanChangX Apr 15, 2024
911b920
Add .gitignore rules to exclude contents of data folder
SeanChangX Apr 15, 2024
39a19dc
Remove local data
SeanChangX Apr 15, 2024
7de0b2a
Update .gitignore
SeanChangX Apr 15, 2024
c1cc807
Update usb device detect func
SeanChangX Apr 15, 2024
c1dbd8b
Regular Update
SeanChangX Apr 16, 2024
1e26475
Update fullscreen mode
SeanChangX Apr 17, 2024
4d27607
Update DIT-2024-12 stm01 SN
SeanChangX Apr 25, 2024
8295042
Update DIT-2024-11 stm01 SN
SeanChangX Apr 25, 2024
6b6778f
Fix udev tty subsystem problem
SeanChangX Apr 26, 2024
a0ba4d6
Update share folder and docker-compose file
SeanChangX Apr 26, 2024
bdd7cb3
Merge branch 'dev' of github.com:SeanChangX/DIT-Scripts into dev
SeanChangX Apr 26, 2024
c708a8d
Renew data path
SeanChangX Apr 26, 2024
dfb332f
Update web page voltage file path
SeanChangX Apr 26, 2024
5d3261e
Fix the wrong path of voltage.cache
SeanChangX Apr 26, 2024
1c0739c
Update RGB LED dual-core program
SeanChangX Apr 28, 2024
8974b56
Update .arduino libraries and settings
SeanChangX Apr 28, 2024
46ca690
Update Highcharts library and fix chart rendering issue
SeanChangX Apr 29, 2024
413f95a
Add Ladybug communication code
SeanChangX Apr 29, 2024
bc0f9a4
DIT-2024-11 change stm_01
SeanChangX Apr 30, 2024
760667a
Backup share folder
SeanChangX Apr 30, 2024
5bae0ec
Add ladybug.sh
SeanChangX Apr 30, 2024
71f2be5
Update ladybug communication & battery watchdog
SeanChangX May 3, 2024
7a259af
Update BattWD Wi-Fi function
SeanChangX May 23, 2024
2d47420
Update README.md to include DIT-Scripts installation instructions and…
SeanChangX Dec 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
276 changes: 276 additions & 0 deletions .arduino/Battery_watchdog/Battery_watchdog.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
/******************************
Requirements:
Adafruit_NeoPixel
Arduino_JSON
AsyncElegantOTA
AsyncTCP
ESP_Async_WebServer
WiFiManager
******************************/

#include <Arduino.h>
#include <ESPmDNS.h>
#include <WiFi.h>
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager WiFi Configuration Magic
#include <AsyncTCP.h>
#include <AsyncElegantOTA.h>
#include <ESPAsyncWebServer.h>
#include "SPIFFS.h"
#include <Arduino_JSON.h>
#include <Adafruit_NeoPixel.h>

#define LED_PIN D1
#define LED_COUNT 29
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
int mode = 0;

WiFiManager wifiManager;

TaskHandle_t Task1;
TaskHandle_t Task2;

volatile int interruptCounter;
hw_timer_t *timer = NULL;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;

// Create AsyncWebServer object on port 80
AsyncWebServer server(80);

// Create an Event Source on /events
AsyncEventSource events("/events");

// Json Variable to Hold Sensor Readings
JSONVar readings;

uint32_t Vbatt = 0;
float Vbattf = 0.0;
float offset = 0.65;

// Get Sensor Readings and return JSON object
String getSensorReadings() {
readings["sensor"] = String(Vbattf);
readings["GND"] = 0;

// 17.5V-[LOW] 20.5V-[FULL]
if (Vbattf < 3) {
readings["batteryStatus"] = "battery_disconnect";
mode = 2;
} else if (Vbattf < 17.5) {
readings["batteryStatus"] = "low_battery";
mode = 1;
} else {
readings["batteryStatus"] = "normal";
mode = 0;
}

String jsonString = JSON.stringify(readings);
return jsonString;
}

// Initialize SPIFFS
void initSPIFFS() {
if (!SPIFFS.begin()) {
Serial.println("An error has occurred while mounting SPIFFS");
} else {
Serial.println("SPIFFS mounted successfully");
}
}

// Initialize WiFi
void initWiFi() {
wifiManager.autoConnect("DIT-2024-12-ESP");
if (!MDNS.begin("dit-2024-12-esp")) {
Serial.println("Error starting mDNS");
return;
}
Serial.println(WiFi.localIP());
}

void voltmeter() {
Vbatt = 0;
for (int i = 0; i < 64; i++) {
Vbatt = Vbatt + analogReadMilliVolts(A0); // ADC with correction
}
Vbattf = 7.81 * Vbatt / 64 / 1000.0 + offset; // R1 = 1.5M ohm, R2 = 220k ohm
if (Vbattf < 3) Vbattf = 0.00;
Serial.print("batteryVoltage:");
Serial.println(Vbattf, 1);
}

void IRAM_ATTR onTimer() {
portENTER_CRITICAL_ISR(&timerMux);
interruptCounter++;
portEXIT_CRITICAL_ISR(&timerMux);
}

void setup() {
//create a task that will be executed in the Task1code() function, with priority 1 and executed on core 0
xTaskCreatePinnedToCore(
Task1code, /* Task function. */
"Task1", /* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
1, /* priority of the task */
&Task1, /* Task handle to keep track of created task */
0); /* pin task to core 0 */
delay(500);

//create a task that will be executed in the Task2code() function, with priority 1 and executed on core 1
xTaskCreatePinnedToCore(
Task2code, /* Task function. */
"Task2", /* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
1, /* priority of the task */
&Task2, /* Task handle to keep track of created task */
1); /* pin task to core 1 */
delay(500);

strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP
strip.setBrightness(128); // Set BRIGHTNESS

timer = timerBegin(0, 80, true);
timerAttachInterrupt(timer, &onTimer, true);
timerAlarmWrite(timer, 1000000, true);
timerAlarmEnable(timer);

pinMode(A0, INPUT); // ADC

// Serial port for debugging purposes
Serial.begin(115200);
initWiFi();
initSPIFFS();

// Web Server Root URL
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(SPIFFS, "/index.html", "text/html");
});

server.serveStatic("/", SPIFFS, "/");

// Request for the latest sensor readings
server.on("/readings", HTTP_GET, [](AsyncWebServerRequest *request) {
String json = getSensorReadings();
request->send(200, "application/json", json);
json = String();
});

events.onConnect([](AsyncEventSourceClient *client) {
if (client->lastId()) {
Serial.printf("Client reconnected! Last message ID that it got is: %u\n", client->lastId());
}
// send event with message "hello!", id current millis
// and set reconnect delay to 1 second
client->send("Test", NULL, millis(), 10000);
});
server.addHandler(&events);

// Start server
AsyncElegantOTA.begin(&server); // Start ElegantOTA
server.begin();
}

void Task1code(void *pvParameters) {
Serial.print("Task1 running on core ");
Serial.println(xPortGetCoreID());

for (;;) {
voltmeter();
if (interruptCounter > 0) {

portENTER_CRITICAL(&timerMux);
interruptCounter--;
portEXIT_CRITICAL(&timerMux);

events.send(getSensorReadings().c_str(), "new_readings", millis());
}
}
}

void Task2code(void *pvParameters) {
Serial.print("Task2 running on core ");
Serial.println(xPortGetCoreID());

for (;;) {
switch (mode)
{
case 2:
colorWipe(strip.Color(0, 0, 255), 50);
colorWipe(strip.Color(0, 0, 0), 50);
break;
case 1:
colorWipe(strip.Color(255, 0, 0), 50);
colorWipe(strip.Color(0, 0, 0), 50);
break;
default:
rainbow(1);
}
// theaterChase(strip.Color(255, 0, 0), 50);
// theaterChaseRainbow(50);
}
}

void loop() {}

void colorWipe(uint32_t color, int wait) {
for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
strip.show(); // Update strip to match
delay(wait); // Pause for a moment
}
}

void theaterChase(uint32_t color, int wait) {
for (int a = 0; a < 10; a++) { // Repeat 10 times...
for (int b = 0; b < 3; b++) { // 'b' counts from 0 to 2...
strip.clear(); // Set all pixels in RAM to 0 (off)
// 'c' counts up from 'b' to end of strip in steps of 3...
for (int c = b; c < strip.numPixels(); c += 3) {
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
}
strip.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
}
}

void rainbow(int wait) {
// Hue of first pixel runs 5 complete loops through the color wheel.
// Color wheel has a range of 65536 but it's OK if we roll over, so
// just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
// means we'll make 5*65536/256 = 1280 passes through this loop:
for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256) {
// strip.rainbow() can take a single argument (first pixel hue) or
// optionally a few extras: number of rainbow repetitions (default 1),
// saturation and value (brightness) (both 0-255, similar to the
// ColorHSV() function, default 255), and a true/false flag for whether
// to apply gamma correction to provide 'truer' colors (default true).
strip.rainbow(firstPixelHue);
// Above line is equivalent to:
// strip.rainbow(firstPixelHue, 1, 255, 255, true);
strip.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
}

void theaterChaseRainbow(int wait) {
int firstPixelHue = 0; // First pixel starts at red (hue 0)
for (int a = 0; a < 30; a++) { // Repeat 30 times...
for (int b = 0; b < 3; b++) { // 'b' counts from 0 to 2...
strip.clear(); // Set all pixels in RAM to 0 (off)
// 'c' counts up from 'b' to end of strip in increments of 3...
for (int c = b; c < strip.numPixels(); c += 3) {
// hue of pixel 'c' is offset by an amount to make one full
// revolution of the color wheel (range 65536) along the length
// of the strip (strip.numPixels() steps):
int hue = firstPixelHue + c * 65536L / strip.numPixels();
uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
}
strip.show(); // Update strip with new contents
delay(wait); // Pause for a moment
firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
}
}
}
Binary file not shown.
8 changes: 8 additions & 0 deletions .arduino/Battery_watchdog/Serial.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

PORT="/dev/ttyACM0"
BAUD=115200
stty -F $PORT $BAUD

cat < $PORT

Binary file added .arduino/Battery_watchdog/data/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions .arduino/Battery_watchdog/data/highcharts.js

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions .arduino/Battery_watchdog/data/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<title>DIT Robotics</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/png" href="favicon.png">
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://code.highcharts.com/highcharts.js"></script>
<script>
if (typeof Highcharts === 'undefined') {
document.write('<script src="highcharts.js"><\/script>');
}
</script>
</head>
<body>
<div class="topnav">
<h1>ROBOT STATUS PANEL</h1>
</div>
<div class="content">
<div class="card-grid">
<div class="card">
<p class="card-title">Battery Status</p>
<div id="chart-sensor" class="chart-container"></div>
</div>
</div>
</div>
<script src="script.js"></script>
<div id="batteryStatus">Battery Status: unknown</div>
</body>
</html>
Loading