Re: Elektronik Bastelei mit Arduino (Selbstbau Tacho, DZM etc)
Verfasst: 22. Jul 2018
Sehr aufmerksam. Danke, ja ich benutze I2C.
LG Roland
LG Roland
Das Forum für Petrolheads, Garagenschrauber, Ölfinger, Frickelracer und Alteisentreiber
https://www.caferacer-forum.de/
Code: Alles auswählen
#include <EEPROM.h>
#include <RunningAverage.h>
#include <Wire.h>
#include "OneButton.h"
#include <U8g2lib.h>
#include "RTClib.h"
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ 16, /* data=*/ 17); // ESP32 Thing, HW I2C with pin remapping
RTC_DS3231 rtc;
const uint16_t Entprellzeit = 20; // in ms
volatile uint32_t lastMillis = 0;
RunningAverage myRA(5);
volatile short geschwindigkeit;
const int buttonPin = 4;
const int reedPin = 3;
int screen = 0;
volatile int RotationCounter = 0;
OneButton button(buttonPin, true);
const int RadUmfang = 1862;
char Speed[10];
uint64_t GesamtMillimeter;
uint32_t TripMillimeter;
int GesamtMillimeter_ADDR = 0;
int TripMillimeter_ADDR = GesamtMillimeter_ADDR + 8; //Gesamtmillimeter ist 64bit Zahl --> braucht 8 Byte im EEPROM
char TripKm[10];
char GesamtKm[10];
boolean reset = false;
boolean MotorradFaehrt = false;
boolean ShowLogo = false;
boolean beimNaechstenStopDatenSichern = false;
#define logo_width 128
#define logo_height 62
const unsigned char logo[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xc0, 0xff, 0x0f, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1e, 0x00, 0x00, 0x00, 0x7f, 0xff, 0x7f, 0x3c, 0x03, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xe0, 0x1f, 0x00, 0x00, 0xc0, 0xfd, 0xff, 0xff, 0x3d,
0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00, 0x78,
0xff, 0xff, 0xff, 0x7b, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe,
0x1f, 0x00, 0x00, 0xcc, 0xff, 0xff, 0xff, 0x7b, 0x3e, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0xff, 0x1f, 0x00, 0x00, 0xcc, 0xff, 0xff, 0xff, 0x7b,
0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0x1f, 0x00, 0x00, 0xf6,
0xff, 0xff, 0xff, 0xff, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff,
0x1f, 0x00, 0x00, 0xfa, 0xff, 0xff, 0xff, 0xff, 0x7c, 0x00, 0x00, 0x00,
0x00, 0x00, 0xf8, 0xff, 0x1f, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x7f,
0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xcf, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xe3, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f,
0xe3, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x03,
0x00, 0x00, 0x80, 0xc7, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x10, 0x00, 0x00, 0x03, 0xc0, 0x01, 0x00, 0x07, 0xc3, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x01, 0xe0, 0x0f, 0x00, 0x03,
0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x80, 0x01,
0x63, 0x9e, 0x01, 0x03, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xc0, 0x00, 0x80, 0x0c, 0x6f, 0xc8, 0x87, 0x01, 0x0e, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0xe0, 0x7c, 0xef, 0xef, 0x8d, 0x01,
0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0xc0, 0x00, 0xe0, 0x7c,
0xef, 0xef, 0x8d, 0x01, 0x1c, 0x1f, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x07,
0x80, 0x01, 0xe0, 0xfc, 0xe3, 0x6f, 0xf8, 0x00, 0xbe, 0xff, 0x03, 0x00,
0x00, 0xf0, 0xff, 0x3f, 0x00, 0x07, 0x60, 0xfc, 0xe3, 0xf0, 0xfd, 0x00,
0xbc, 0xff, 0x0f, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x00, 0x0e, 0x70, 0x3c,
0xaf, 0x77, 0x7e, 0x00, 0x3d, 0xff, 0x7f, 0x00, 0x00, 0xff, 0xff, 0xff,
0x01, 0x0e, 0x10, 0x04, 0xe3, 0xb7, 0x73, 0x80, 0x73, 0xff, 0xff, 0x00,
0x80, 0xff, 0xff, 0xff, 0x03, 0x18, 0x18, 0x00, 0xe0, 0xd9, 0x19, 0xc0,
0x73, 0xff, 0x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01, 0xf8, 0x3f, 0x60, 0xfe, 0x03,
0xc0, 0xff, 0x07, 0xff, 0x0f, 0x00, 0x00, 0xfe, 0xff, 0x7f, 0x00, 0xf0,
0xff, 0xe0, 0xff, 0x03, 0x80, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00,
0xf0, 0x0f, 0x00, 0xc0, 0xff, 0xff, 0xff, 0x01, 0x80, 0xff, 0xff, 0xff,
0x03, 0x00, 0x00, 0x00, 0xf0, 0x0f, 0x00, 0xc0, 0xff, 0xff, 0xff, 0x01,
0x00, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0xff, 0xff, 0xff, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xf0, 0xff, 0x7f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x0f, 0x00,
0x00, 0xc0, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xf0, 0xff, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
#define tachoSymbol_width 48
#define tachoSymbol_height 30
const unsigned char tachoSymbol[] PROGMEM = {
0x00, 0x00, 0xf0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00,
0x00, 0xc0, 0xff, 0xff, 0x03, 0x00, 0x00, 0xf0, 0xff, 0xff, 0x0f, 0x00,
0x00, 0xfc, 0xff, 0xff, 0x3f, 0x00, 0x00, 0xfe, 0xcf, 0xf3, 0x7f, 0x00,
0x00, 0xff, 0xc1, 0x83, 0xff, 0x00, 0x80, 0x7f, 0xc0, 0x03, 0xfe, 0x01,
0xc0, 0x1f, 0xc0, 0x03, 0xf8, 0x03, 0xe0, 0x0f, 0xc0, 0x03, 0xf0, 0x07,
0xf0, 0x87, 0x81, 0x01, 0xe0, 0x0f, 0xf8, 0x83, 0x03, 0x00, 0xc0, 0x0f,
0xf8, 0x81, 0x07, 0x00, 0x80, 0x1f, 0xfc, 0x80, 0x07, 0x00, 0x00, 0x3f,
0x7c, 0x00, 0x0f, 0x00, 0x00, 0x3e, 0x7e, 0x00, 0x1f, 0x00, 0x00, 0x7e,
0x3e, 0x00, 0x3e, 0x00, 0x00, 0x7c, 0x3e, 0x00, 0x3e, 0x00, 0x00, 0x7c,
0x3e, 0x00, 0x7c, 0x00, 0x00, 0x7c, 0x1f, 0x00, 0xfc, 0x03, 0x00, 0xf8,
0x1f, 0x00, 0xf8, 0x0f, 0x00, 0xf8, 0x1f, 0x00, 0xf8, 0x1f, 0x00, 0xf8,
0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0xfe, 0xff, 0x3f, 0xfc, 0xff, 0x7f,
0xfe, 0xff, 0x3f, 0xfc, 0xff, 0x7f, 0xfc, 0xff, 0x3f, 0xfc, 0xff, 0x3f,
0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xf0, 0x0f, 0x00, 0x00,
0x00, 0x00, 0xf0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00 };
#define thermometer_width 24
#define thermometer_height 64
const unsigned char thermometer_Symbol[] PROGMEM = {
0x00, 0x3c, 0x00, 0x00, 0xff, 0x00, 0x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define route_width 34
#define route_height 34
const unsigned char route_bits[] PROGMEM = {
0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0xee, 0x00, 0x00, 0x00,
0x00, 0xbb, 0x01, 0x00, 0x00, 0x00, 0x7d, 0x03, 0x00, 0x00, 0x80, 0xc7,
0x03, 0x00, 0x00, 0x80, 0x87, 0x02, 0x00, 0x00, 0x80, 0xc7, 0x03, 0x00,
0x00, 0x00, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x7b, 0x01, 0x00, 0x00, 0x00,
0x83, 0x01, 0x00, 0x00, 0x00, 0x86, 0x00, 0x00, 0x00, 0x00, 0xc4, 0x00,
0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00,
0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x20, 0x00, 0x00, 0x10,
0x00, 0xfc, 0x01, 0x00, 0x00, 0x00, 0x06, 0x03, 0x00, 0x1e, 0x00, 0xfa,
0x02, 0xe0, 0x0f, 0x00, 0xdf, 0x06, 0x7f, 0x00, 0x00, 0x8d, 0xc7, 0x07,
0x00, 0x00, 0x85, 0x07, 0x3f, 0x00, 0x00, 0x8f, 0x07, 0xf8, 0x01, 0x00,
0xfa, 0x02, 0x80, 0x1f, 0x00, 0x26, 0x03, 0x00, 0x7e, 0x00, 0x04, 0xe1,
0xff, 0x7f, 0x00, 0x8c, 0xf1, 0x00, 0x00, 0x00, 0x88, 0xc0, 0x00, 0x00,
0x00, 0xd8, 0x80, 0x01, 0x00, 0x00, 0x70, 0x00, 0x03, 0x00, 0x00, 0x30,
0x00, 0x06, 0x00, 0x00, 0x20, 0xff, 0x07, 0x00, 0x00, 0x80, 0x1f, 0x00,
0x00, 0x00 };
void setup() {
// Serial.begin(9600); // open the serial port at 9600 bps:
if (reset) { resetEEPROM(); } //alles auf 0 setzen
pinMode(reedPin, INPUT_PULLUP); // Reed-Sensor an Pin 3
pinMode(buttonPin, INPUT_PULLUP); // Taster an Pin 2
EIFR = (1 << INTF1); //verhindert fälschliches Aufrufen der ISR revs() bei Startup --> https://github.com/arduino/Arduino/issues/510
attachInterrupt(digitalPinToInterrupt(reedPin), revs, RISING);
getMileage(); //gespeicherten Tachostand abrufen (eeprom-adresse mit höchstem Zählerstand suchen)
myRA.clear();
button.attachClick(klick);
button.attachLongPressStop(langDruck);
u8g2.begin();
u8g2_prepare();
u8g2.clearBuffer();
u8g2.drawXBMP( 0, 0, logo_width, logo_height, logo);
u8g2.sendBuffer();
delay(2000);
}
void loop() {
button.tick();
u8g2.clearBuffer();
if (MotorradFaehrt) {
myRA.addValue(geschwindigkeit); // Wert zur Mittelwerberechnung hinzufügen
GesamtMillimeter += RadUmfang;
TripMillimeter += RadUmfang;
MotorradFaehrt = false;
if (geschwindigkeit > 30) beimNaechstenStopDatenSichern = true; //Flag setzen um Tachostand beim nächsten Stop wegzuschreiben
}
if (millis()-lastMillis >= 10000) { //wenn keine Radumdrehung innerhalb von 10 Sek stattgefunden hat --> Logo zeigen
u8g2.drawXBMP( 0, 0, logo_width, logo_height, logo);
ShowLogo = true;
if (beimNaechstenStopDatenSichern) { //Tachostand nur dann ins EEPROM schreiben, wenn vorher über 30km/h gefahren wurde
saveMileage();
beimNaechstenStopDatenSichern = false;
}
} else {
draw();
}
u8g2.sendBuffer();
if (millis()-lastMillis >= 2000) {
myRA.clear(); //wenn keine Radumdrehung innerhalb von 2 Sek stattgefunden hat --> Geschwindigkeit nullen
}
if (RotationCounter >= 10) { //Tachostand ca. alle 500m sichern (260 umdrehungen);
RotationCounter = 0;
saveMileage();
}
}
void draw() {
short VAnzeige = myRA.getAverage(); // Mittelwert errechnen
DateTime now = rtc.now();
int hunderter = (TripMillimeter / 100000) % 10;
int tausender = TripMillimeter / 1000000;
sprintf(GesamtKm, "%6lukm",(uint32_t)(GesamtMillimeter/1000000));
sprintf(TripKm, "%5d.%dkm", tausender, hunderter);
sprintf(Speed, "%3d", VAnzeige);
switch (screen) {
case 0:
u8g2.drawXBMP( 80, 0, tachoSymbol_width, tachoSymbol_height, tachoSymbol);
u8g2.setFont(u8g2_font_logisoso38_tn);
u8g2.drawStr( 0, 15, Speed);
u8g2.setFont(u8g2_font_logisoso20_tr);
u8g2.drawStr( 75, 32, "kmh");
break;
case 1:
u8g2.setFont(u8g2_font_logisoso38_tn);
u8g2.setCursor(5,15);
if (now.hour() < 10) u8g2.print("0");
u8g2.print(now.hour());
u8g2.print(":");
if (now.minute() < 10) u8g2.print("0");
u8g2.print(now.minute());
break;
case 2:
u8g2.setFont(u8g2_font_logisoso20_tr);
u8g2.drawStr( 0, 10, "Trip:");
u8g2.drawStr( 0, 40, TripKm);
u8g2.drawXBMP( 80, 0, route_width, route_height, route_bits);
break;
case 3:
u8g2.drawStr( 0, 40, TripKm);
u8g2.drawStr( 5, 10, GesamtKm);
break;
case 4:
u8g2.setFont(u8g2_font_logisoso38_tn);
u8g2.setCursor(0, 15);
u8g2.print(tempDS3231(), 1);
u8g2.drawCircle(98, 20, 5, U8G2_DRAW_ALL); //nicht besonders schön, aber speicher-optimalste Veriante ??
u8g2.drawCircle(98, 20, 4, U8G2_DRAW_ALL);
u8g2.drawXBMP( 105, 0, thermometer_width, thermometer_height, thermometer_Symbol);
break;
}
}
void u8g2_prepare(void) {
u8g2.setFontRefHeightExtendedText();
u8g2.setDrawColor(1);
u8g2.setFontPosTop();
u8g2.setFontDirection(0);
}
void revs() { // Interrupt-Routine
uint32_t jetztMillis = millis();
if (jetztMillis - lastMillis >= Entprellzeit) { // ignorieren wenn <= 10ms (Kontaktpreller)
geschwindigkeit = RadUmfang*3.6/(jetztMillis-lastMillis); // Geschwindigkeit: 1 Interrupt alle 1861mm (Radumfang)
lastMillis = millis();
RotationCounter += 1;
MotorradFaehrt = true;
}
}
void klick() { //durchtoggeln der Screens
screen++;
if (screen > 4) screen= 0;
if (ShowLogo) { //falls Logo angezeigt und Knopf gedrückt wird --> Logo-Timer wieder auf 10sek setzen und Geschwindigkeit anzeigen
ShowLogo = false;
lastMillis = millis();
screen = 0;
}
}
void langDruck() {
if (screen == 2) {
TripMillimeter = 0; //Trip zurücksetzen
EEPROM.put(TripMillimeter_ADDR, TripMillimeter);
}
}
float tempDS3231() { // Die Temperatur des DS3231 auslesen
float temp;
int msb, lsb;
Wire.beginTransmission(0x68);
Wire.write(0x11);
Wire.endTransmission();
Wire.requestFrom(0x68, 2);
msb = Wire.read();
lsb = Wire.read();
temp=((msb << 2) + (lsb >> 6) ) /4.0;
return temp;
}
void getMileage(){ //EEPROM-Adresse mit dem höchsten Tachostand suchen
uint64_t GesamtMillimeter_vgl;
EEPROM.get(GesamtMillimeter_ADDR, GesamtMillimeter); //Absprungbasis bei Adresse=0
for (int pos=0; pos<=1008; pos=pos + 12){ //EEProm.length = 0-1023
EEPROM.get(pos, GesamtMillimeter_vgl);
if (GesamtMillimeter_vgl > GesamtMillimeter){ //falls höherer KM-Stand gefunden wurde, diesen übernehmen und weitersuchen
GesamtMillimeter = GesamtMillimeter_vgl;
GesamtMillimeter_ADDR = pos;
}
}
TripMillimeter_ADDR=GesamtMillimeter_ADDR + 8;
EEPROM.get(GesamtMillimeter_ADDR, GesamtMillimeter);
EEPROM.get(TripMillimeter_ADDR, TripMillimeter);
}
void saveMileage() {
GesamtMillimeter_ADDR += 12; //immer in neue Zelle schreiben --> verlängert EEPROM Lebensdauer (Gesamtmillimeter 8 Byte, TripMillimeter 4 Byte -> Sprung um 12Byte
if (GesamtMillimeter_ADDR > 1008) {GesamtMillimeter_ADDR = 0;}
TripMillimeter_ADDR = GesamtMillimeter_ADDR + 8; //Gesamtmillimeter ist 64bit Zahl --> braucht 8 Byte im EEPROM
EEPROM.put(GesamtMillimeter_ADDR, GesamtMillimeter);
EEPROM.put(TripMillimeter_ADDR, TripMillimeter);
}
void resetEEPROM() {
for (unsigned int i = 0 ; i < EEPROM.length() ; i++) {
EEPROM.write(i, 0);
}
GesamtMillimeter = 0;
TripMillimeter = 0;
//Serial.println(F("FACTORY-RESET"));
}
Wozu denn alles da rein pressen? Es muss dort doch nur das Display sitzen. Den Rest kannst du mit Leitungen verbinden und die Steuerung würde ich irgendwo unter dem Tank oder Sitz möglichst Vibrationsgeschützt platzieren.SebastianM hat geschrieben: 13. Aug 2018 Die größte Herausforderung wird meines Erachtens aber noch die mechanische Integration ins Mopped; das Ganze muss in einen Becher mit 40mm Außendurchmesser gepresst werden, damit es in die Gabelbrücke meiner Bolle passt (siehe Photo unten).