Skip to content

Commit

Permalink
Fix multiple minor issues and minor cleanup; Remove BoardDefs.h (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecoreng authored Oct 16, 2023
1 parent 6bdf9b1 commit ee85f47
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 94 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
Head over to the discord server to discuss this firmware: https://discord.gg/zw377qhj9c

## What is this?
Firmware source code for ESP8266 that is compatible with SimHub. It's derived from what SimHub lets you setup, but tweaked with a thin compatibility layer for the ESP8266.
Firmware source code for ESP8266 and ESP32 that is compatible with SimHub. It's derived from what SimHub lets you setup, but tweaked with a thin compatibility layer for the ESP8266 and ESP32.

## Why would you want to do this?
ESP8266 is cheaper and more powerful that most arduinos boards and fairly popular in the IoT Community.
ESP8266 is cheaper and more powerful that most arduinos boards and fairly popular in the IoT Community. The ESP32 is a very handy little monster to use too.

## How To
- Download this code
Expand All @@ -30,7 +30,7 @@ the serial port) and we allow the modified Arduino SimHub client to consume it f
Set the [preprocessor directive](https://cplusplus.com/doc/tutorial/preprocessor/) called INCLUDE_WIFI to true (in src/main.cpp). Set DEBUG_TCP_BRIDGE to true as well, and set `monitor_speed = 115200` in `platformio.ini`.

## How to connect the ESP to your WiFi
Upload a [WiFi enabled](https://github.com/eCrowneEng/ESP-SimHub/blob/main/src/main.cpp#L4) firmware. Connect USB to computer and open the serial monitor with `115200` baud rate (to catch debug messages). Power the ESP up. It will itself create a new WiFi network (SHC-{a bunch of letters and numbers}) that you can connect to from your phone or computer. Connect and expect a [captive portal](https://en.wikipedia.org/wiki/Captive_portal). Pick the option to "scan".. scan the available WiFi networks, pick the one you want to connect to and proceed.
Upload a [WiFi enabled](https://github.com/eCrowneEng/ESP-SimHub/blob/main/src/main.cpp#L4) firmware. Connect USB to computer and open the serial monitor with `115200` baud rate (to catch debug messages). Power the ESP up. It will itself create a new WiFi network (ESP-{a bunch of letters and numbers}) that you can connect to from your phone or computer. Connect to that network and navigate to `http://192.168.4.1`, observe a [captive portal](https://en.wikipedia.org/wiki/Captive_portal). Configure your WiFi and then disconnect.

Once the ESP is connected to a network, it won't create its own. The device should output the IP address it's using, write it down, you'll need it.

Expand All @@ -47,5 +47,5 @@ Some Arduino APIs for the ESP32 are different, so not everything will work out o

### How to enable ESP32
- Open `platformio.ini`, comment out the ESP8266 env and Uncomment the ESP32 env. Also specify your board in the env, by default is set to something like `esp32doit-devkit-v1` because I owned this board, but there are tons of boards for the ESP32, as you can see [here](https://docs.platformio.org/en/latest/boards/index.html#espressif-32). Click on one and it will show you what's its id.
- Go to `lib/BoardDefs.h` and comment out `#define ESP8266` and uncomment `#define ESP32`.
- Make sure to use GPIO_NUM_XX aliases of pins, as opposed to D1, D2, D3.. etc
- In `src/main.cpp` comment out `#define ESP8266` and uncomment `#define ESP32`.
- Make sure to use the correct pin numbers for the ESP32 as opposed to aliases such as D1, D2, D3.. etc
9 changes: 0 additions & 9 deletions lib/EspSimHub/BoardDefs.h

This file was deleted.

7 changes: 0 additions & 7 deletions lib/EspSimHub/BoardWifi.h

This file was deleted.

11 changes: 6 additions & 5 deletions lib/EspSimHub/EspSimHub.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#pragma once
#include <BoardDefs.h>
#include <BoardWifi.h>
#ifdef ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif


// Fake an Arduino Mega
#define SIGNATURE_0 0x1E
#define SIGNATURE_1 0x98
#define SIGNATURE_2 0x01

// Configure FASTLED with proper pin order
#define FASTLED_ESP8266_NODEMCU_PIN_ORDER

// A unique identifier for the device.
// in the future we could use the bytes to generate some
// other format (ala UUID), but now it's just a unique
Expand Down
3 changes: 2 additions & 1 deletion src/SHGLCD_NOKIA.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@


// Adafruit_PCD8544 display = Adafruit_PCD8544(SCLK, DIN, DC, CS or SCE, RST);
Adafruit_PCD8544 nokia1 = Adafruit_PCD8544(A0, A1, A2, A4, A3);
#pragma message("Make sure these pins are configured properly");
Adafruit_PCD8544 nokia1 = Adafruit_PCD8544(0, 1, 2, 4, 3);
Adafruit_PCD8544 * nokia[] = { &nokia1 };

class SHGLCD_NOKIA : public SHGLCD_Base
Expand Down
26 changes: 13 additions & 13 deletions src/SHGLCD_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ class SHGLCD_Base
{
private:
//uint8_t fontSize;
int16_t posX;
int16_t posY;
char action;
int16_t posX = 0;
int16_t posY = 0;
char action = 0;
int16_t v[4 * 2];
uint16_t color;
int16_t w;
int16_t h;
int16_t r;
uint16_t color = 0;
int16_t w = 0;
int16_t h = 0;
int16_t r = 0;
uint8_t align = 0;
//boolean wrap = 0;

int16_t boundX;
int16_t boundY;
uint16_t boundW;
uint16_t boundH;
int16_t boundX = 0;
int16_t boundY = 0;
uint16_t boundW = 0;
uint16_t boundH = 0;

uint8_t nokiaIndex;
uint8_t fontType;
uint8_t nokiaIndex = 0;
uint8_t fontType = 0;

Adafruit_GFX* currentNokia;

Expand Down
9 changes: 4 additions & 5 deletions src/SHI2CLcdBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

#include <Arduino.h>


class SHI2CLcdBase {
private:
int _width;
int _height;
int _width = 0;
int _height = 0;
public:

void begin(int width, int height, bool test) {
Expand All @@ -28,8 +27,8 @@ class SHI2CLcdBase {
}
}

virtual void setCursor(int x, int y);
virtual void print(String s);
virtual void setCursor(int x, int y) = 0;
virtual void print(String s) = 0;

};

Expand Down
11 changes: 5 additions & 6 deletions src/SHI2CLcd_PCF8574AT.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
#define __I2CLCD_H__

#include <Arduino.h>
#include "SHI2CLcdBase.h"

#include <SHI2CLcdBase.h>

class SHI2CLcd : public SHI2CLcdBase {
private:
LiquidCrystal_I2C * I2CLCD;

public:
void begin(LiquidCrystal_I2C * I2CLCDInstance, int width, int height, bool test) {
SHI2CLcdBase::begin(width, height, test);
// SHI2CLcdBase::begin(width, height, test);
I2CLCD = I2CLCDInstance;
I2CLCD->init();
I2CLCD->backlight();
I2CLCD->print("Hello world...");
if(!test)
I2CLCD->clear();
if(!test) {
I2CLCD->clear();
}
}


Expand All @@ -29,7 +29,6 @@ class SHI2CLcd : public SHI2CLcdBase {
I2CLCD->print(s);
}


};

#endif
2 changes: 1 addition & 1 deletion src/SHRGBLedsBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SHRGBLedsBase {

public:

virtual void show();
virtual void show() = 0;

void clear() {
for (int j = 0; j < _maxLeds; j++) {
Expand Down
6 changes: 3 additions & 3 deletions src/SHShakeitBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class SHShakeitBase {
unsigned long lastRead = 0;

public:
virtual uint8_t motorCount();
virtual String providerName();
virtual uint8_t motorCount() = 0;
virtual String providerName() = 0;

virtual void safetyStop() {
uint8_t motorcount = motorCount();
Expand Down Expand Up @@ -41,7 +41,7 @@ class SHShakeitBase {
}

protected:
virtual void setMotorOutput(uint8_t motorIdx, uint8_t value);
virtual void setMotorOutput(uint8_t motorIdx, uint8_t value) = 0;
};

#endif
2 changes: 1 addition & 1 deletion src/SHShakeitDualVNH5019.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ DualVNH5019MotorShield dualVNH5019MotorShield;

class SHShakeitDualVNH5019 : public SHShakeitBase {
private:
bool _reverseDirection;
bool _reverseDirection = false;
public:
uint8_t motorCount() {
return 2;
Expand Down
12 changes: 6 additions & 6 deletions src/SHShakeitL298N.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

class SHShakeitL298N : public SHShakeitBase {
private:
byte pinL98N_enA;
byte pinL98N_enB;
byte pinL98N_in1;
byte pinL98N_in2;
byte pinL98N_in3;
byte pinL98N_in4;
byte pinL98N_enA = 0;
byte pinL98N_enB = 0;
byte pinL98N_in1 = 0;
byte pinL98N_in2 = 0;
byte pinL98N_in3 = 0;
byte pinL98N_in4 = 0;
public:
uint8_t motorCount() {
return 2;
Expand Down
1 change: 0 additions & 1 deletion src/SHTM1637.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ void TM1637_SetDisplayFromSerial(TM1637Display* screen)

void TM1637_Init() {
for (int i = 0; i < TM1637_ENABLEDMODULES; i++) {
TM1637_screens[i]->init();
TM1637_screens[i]->setBrightness(4);
TM1637_screens[i]->clear();
}
Expand Down
31 changes: 15 additions & 16 deletions src/SHTM1637_6D.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
#include "TM1637_6D.h"
#include "TM1637Display.h"

TM1637_6D TM1637_6D_module1(TM1637_6D_CLK1, TM1637_6D_DIO1);
TM1637_6D TM1637_6D_module2(TM1637_6D_CLK2, TM1637_6D_DIO2);
TM1637_6D TM1637_6D_module3(TM1637_6D_CLK3, TM1637_6D_DIO3);
TM1637_6D TM1637_6D_module4(TM1637_6D_CLK4, TM1637_6D_DIO4);
TM1637_6D TM1637_6D_module5(TM1637_6D_CLK5, TM1637_6D_DIO5);
TM1637_6D TM1637_6D_module6(TM1637_6D_CLK6, TM1637_6D_DIO6);
TM1637_6D TM1637_6D_module7(TM1637_6D_CLK7, TM1637_6D_DIO7);
TM1637_6D TM1637_6D_module8(TM1637_6D_CLK8, TM1637_6D_DIO8);
TM1637Display TM1637_6D_module1(TM1637_6D_CLK1, TM1637_6D_DIO1);
TM1637Display TM1637_6D_module2(TM1637_6D_CLK2, TM1637_6D_DIO2);
TM1637Display TM1637_6D_module3(TM1637_6D_CLK3, TM1637_6D_DIO3);
TM1637Display TM1637_6D_module4(TM1637_6D_CLK4, TM1637_6D_DIO4);
TM1637Display TM1637_6D_module5(TM1637_6D_CLK5, TM1637_6D_DIO5);
TM1637Display TM1637_6D_module6(TM1637_6D_CLK6, TM1637_6D_DIO6);
TM1637Display TM1637_6D_module7(TM1637_6D_CLK7, TM1637_6D_DIO7);
TM1637Display TM1637_6D_module8(TM1637_6D_CLK8, TM1637_6D_DIO8);

TM1637_6D* TM1637_6D_screens[] = { &TM1637_6D_module1, &TM1637_6D_module2, &TM1637_6D_module3, &TM1637_6D_module4, &TM1637_6D_module5, &TM1637_6D_module6, &TM1637_6D_module7, &TM1637_6D_module8 };
TM1637Display* TM1637_6D_screens[] = { &TM1637_6D_module1, &TM1637_6D_module2, &TM1637_6D_module3, &TM1637_6D_module4, &TM1637_6D_module5, &TM1637_6D_module6, &TM1637_6D_module7, &TM1637_6D_module8 };

uint8_t TM1637_6D_screens_digits[6]= { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
uint8_t TM1637_6D_points_digits[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

void TM1637_6D_SetDisplayFromSerial(TM1637_6D* screen)
void TM1637_6D_SetDisplayFromSerial(TM1637Display* screen)
{

#pragma message("This code hasnt been tested, but it was adapted to use the same library we installed previously");
#pragma message("Let us know if it works in a GitHub issue or a message in the Discord");
for (int i = 0; i < 6; i++) {
TM1637_6D_screens_digits[i] = (uint8_t)FlowSerialTimedRead();
screen->encodeDigit(TM1637_6D_screens_digits[i]);
}
screen->displayRaw(TM1637_6D_screens_digits);

// Skip 2 remaining chars
for (int i = 0; i < 2; i++) {
Expand All @@ -30,8 +31,6 @@ void TM1637_6D_SetDisplayFromSerial(TM1637_6D* screen)

void TM1637_6D_Init() {
for (int i = 0; i < TM1637_6D_ENABLEDMODULES; i++) {
TM1637_6D_screens[i]->init();
//TM1637_6D_screens[i]->set(4);
TM1637_6D_screens[i]->clearDisplay();
TM1637_6D_screens[i]->clear();
}
}
Loading

0 comments on commit ee85f47

Please sign in to comment.