Skip to content

Commit

Permalink
feat (HW 2.1) upgrade to hardware version 2.1 and implement related f…
Browse files Browse the repository at this point in the history
…eatures (#45)

* Push from internal dev branch

* Bug fixes
  • Loading branch information
TheRealKasumi committed Mar 31, 2023
1 parent 977a841 commit f679476
Show file tree
Hide file tree
Showing 76 changed files with 3,415 additions and 1,103 deletions.
4 changes: 1 addition & 3 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ The project is therefore mostly platform-independent.

![App](documentation/media/readme/app.jpg)

![PCB](documentation/media/readme/pcb-front.jpg)

![PCB](documentation/media/readme/pcb-back.jpg)
![PCB](documentation/media/build/pcb.png)

## Planning

Expand Down
194 changes: 124 additions & 70 deletions documentation/build.md

Large diffs are not rendered by default.

Binary file modified documentation/media/build/pcb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified documentation/media/build/testlight-pinout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed documentation/media/fun/fuse-replacement.jpg
Binary file not shown.
Binary file removed documentation/media/readme/pcb-back.jpg
Binary file not shown.
Binary file removed documentation/media/readme/pcb-front.jpg
Binary file not shown.
122 changes: 68 additions & 54 deletions documentation/part-list.md

Large diffs are not rendered by default.

50 changes: 25 additions & 25 deletions documentation/planning.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ An example could look like this:
| Channel/Zone | Used for |
| ------------ | ------------------- |
| 1 | Dashboard |
| 5 | Center console |
| 2 | Left, front door |
| 6 | Right, front door |
| 3 | Rear, left door |
| 7 | Rear, right door |
| 4 | Footwell lighting 1 |
| 2 | Center console |
| 3 | Left, front door |
| 4 | Right, front door |
| 5 | Rear, left door |
| 6 | Rear, right door |
| 7 | Footwell lighting 1 |
| 8 | Footwell lighting 2 |

TesLight is using digital LEDs, so that it controll each LED individually.
Expand Down Expand Up @@ -80,10 +80,10 @@ The following table assumes that the TesLight controller is placed below the cen
| Zone | LEDs | Type | Cable Length | Physical Channel |
| ----------------- | ---- | ------------------------- | ------------ | ---------------- |
| Dash | 72 | LED strip | 150cm | 1 |
| Centre Console | 4 | Fiber cable and injectors | 150cm | 5 |
| Front Doors | 130 | Light bar (2 in parallel) | 265cm + 50cm | 2, 6 |
| Rear Doors | 92 | Light bar | 405cm + 45cm | 3, 7 |
| Footwell lighting | 4 | LED strip or single LEDs | 100cm | 4, 8 |
| Centre Console | 4 | Fiber cable and injectors | 150cm | 2 |
| Front Doors | 130 | Light bar (2 in parallel) | 265cm + 50cm | 3, 4 |
| Rear Doors | 92 | Light bar | 405cm + 45cm | 5, 6 |
| Footwell lighting | 4 | LED strip or single LEDs | 100cm | 7, 8 |

So for this build we have a total of around 784 LEDs and need ~20m cable with 3 wires.
Also 5m of fibre cable is recommended for use around the centre console.
Expand All @@ -95,23 +95,25 @@ Since this project can make use of many LEDs, the power consumption plays an imp
TesLight can (and should) be built with an onboard regulator.
This ensures that you stay below the limits the hardware can handle without modifications.
The regulator has 2 channels and is capable of providing a total of 6A at 5V, which is around 30W of power.
These 6A are split to 2x 3A on the channels {1, 2, 3, 4} and {5, 6, 7, 8}.
These 6A are split to 2x 3A on the channels {1, 3, 5, 7} and {2, 4, 6, 8}.
The load of the two single channels should not exceed 3A or 15W at maximum.
By default TesLight has a configured power limit of 20W, or 10W per regulator.
If this limit is reached, the brightness is reduced to stay below this limit.
Also a temperature limit of 80°C is enforced by default when the optinal temperature sensors are installed.

If you need to save some money, you can also only build one channel of the regulator.
Then the power output is halfed and the jumper `J2` must be closed.
Then the power output is halfed and the jumper `J1` must be closed.
The full dual channel buld is recommended because otherwise you are very limited on brightness.

If more power is really needed, then an external regulator is required.
In that case all components for the onboard regulator must be removed from the board.
If more power is really needed, then an external regulator is required and the boards input must be bypassed.
In that case all components for the onboard regulator should be removed from the board.
An exception are the capacitors `C3` and `C4`, which should remain on the board.
The jumpers `J1` and `J2` must be closed.
The jumper `J1` should be closed
Instead of powering the board via the power input, it must be powered via an LED output.
Make sure to provide stable 5V to an LED output.

However, be careful when dealing with the high currents an external regulator could provide.
It could significantly heat up your connectors, wires, LEDs or even the TesLight board.
It is NOT recommended going any higher than around 8A in total.
You might need to change the connectors, use thicker wires and thicker copper on the PCB.

Assuming "average" WS2812 LED chips, each channel can draw around 14mA at 5V and maximum brightness.
Expand All @@ -129,20 +131,18 @@ Also it would allow for brightness levels, that are far from practical, especial

In a normal use case, the power provided by the TesLight controller is enough.
It still allows for a decent brightness without having to deal with dangerously high currents.
By default the software ensures that a maximum power draw of around 20W is not exceeded.
You can adjust this value in the UI.
For this calculation to work properly, the LED voltage and current per channel must be configured correctly.
Like mentioned above, by default the software ensures that a maximum power draw of around 20W is not exceeded.
Also the regulator temperature is limited to 80°C when the optional temperature sensors are installed.
You can adjust these limits in the UI.
For the power limit calculation to work properly, the LED voltage and current per channel must be configured correctly.

> What happens when I exceed the power limit of the regulator temporary or permanently?
Generally it is NOT recommended to do so in any way.
The 20W power limit, or 10W per channel, was tested to be a good compromise between brightness and regulator temperature.
Installing the optional temperature sensors to the board will also limit the temperature to 80°C by default.
This temperature can be exceeded without the sensors.
When using a proper LM2596 (not faked ones), it will shut down as soon as a critical current or temperature (115°C) is reached.
Due to the missing power the controller will shut down and is not available via the web-app anymore.
No damange _should_ be taken from this.
Once the regulators cooled down, they should be reset and the controller reboots.
However this is a emergency feature that should not be triggered in normal use.
You are still risking temperatures of up to 115°C on the board.
Keep that in mind when you think you are special and need to exceed limits😛.
Also don't cry at me when you burn something down.
However don't cry at me when you burn something down.
You have been warned.
67 changes: 30 additions & 37 deletions mcu/include/configuration/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,51 +24,44 @@ namespace TesLight
public:
struct SystemConfig
{
// Log config
TesLight::Logger::LogLevel logLevel;

// Light sensor config
TesLight::LightSensor::LightSensorMode lightSensorMode;
uint16_t lightSensorThreshold;
uint16_t lightSensorMinValue;
uint16_t lightSensorMaxValue;

// Power config
uint8_t systemPowerLimit; // W
TesLight::Logger::LogLevel logLevel; // Logging level
TesLight::LightSensor::LightSensorMode lightSensorMode; // Mode of the light sensor
uint16_t lightSensorThreshold; // Threshold value to turn on/off the LEDs
uint16_t lightSensorMinValue; // Minimum value for automatic brightness adjustment
uint16_t lightSensorMaxValue; // Maximum value for automatic brightness adjustment
uint8_t regulatorPowerLimit; // Limit in W
uint8_t regulatorHighTemperature; // Temp in °C where brightness is reduced
uint8_t regulatorCutoffTemperature; // Temp in °C where LEDs are turned off
uint8_t fanMinPwmValue; // Minimum pwm value output to the fan (stall guard)
uint8_t fanMaxPwmValue; // Maximum pwm value output to the fan
uint8_t fanMinTemperature; // Minimum temp in °C where the fan starts
uint8_t fanMaxTemperature; // Maximum temp in °C to run at maximum speed
};

struct LedConfig
{
// Pin Configuration
uint8_t ledPin;
uint16_t ledCount;

// Animation Configuration
uint8_t type;
uint8_t speed;
uint16_t offset;
uint8_t brightness;
bool reverse;
uint8_t fadeSpeed;
uint8_t customField[ANIMATOR_NUM_CUSTOM_FIELDS];

// Power config
uint8_t ledVoltage; // Voltage * 10
uint8_t ledChannelCurrent[3]; // mA
uint8_t ledPin; // Physical pin for the LED output
uint16_t ledCount; // Number of LEDs
uint8_t type; // Type of the animation
uint8_t speed; // Speed of the animation
uint16_t offset; // Offset for the animation
uint8_t brightness; // Brightness of the LED channel
bool reverse; // Reverse the animation
uint8_t fadeSpeed; // Fading speed when turning on/off
uint8_t customField[ANIMATOR_NUM_CUSTOM_FIELDS]; // Custom fields for the animation
uint8_t ledVoltage; // Voltage of the LED x10
uint8_t ledChannelCurrent[3]; // Current for each LED channel per LED in mA
};

struct WiFiConfig
{
// Access point configuration
String accessPointSsid;
String accessPointPassword;
uint8_t accessPointChannel;
bool accessPointHidden;
uint8_t accessPointMaxConnections;

// WiFi network configuration
String wifiSsid;
String wifiPassword;
String accessPointSsid; // SSID for the access point
String accessPointPassword; // Password for the access point
uint8_t accessPointChannel; // Channel for the access point
bool accessPointHidden; // Hide the access point
uint8_t accessPointMaxConnections; // Maximum number of connection to the access point
String wifiSsid; // SSID of a WiFi network
String wifiPassword; // Password of a WiFi network
};

Configuration(FS *fileSystem, const String fileName);
Expand Down
120 changes: 69 additions & 51 deletions mcu/include/configuration/SystemConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,80 +10,98 @@
#define SYSTEM_CONFIGURATION_H

// SD configuration
#define SD_CS_PIN 5
#define SD_SPI_SPEED 4000000
#define SD_MOUNT_POINT "/sd"
#define SD_MAX_FILES 5
#define SD_CS_PIN 5 // CS pin for the SD card
#define SD_SPI_SPEED 4000000 // SPI data rate
#define SD_MOUNT_POINT "/sd" // Mount point for the SD card
#define SD_MAX_FILES 5 // Maximum number of open files

// Logging configuration
#define SERIAL_BAUD_RATE 460800
#define LOG_FILE_NAME "/system_log.txt"
#define LOG_DEFAULT_LEVEL TesLight::Logger::LogLevel::INFO
#define SERIAL_BAUD_RATE 460800 // Serial baud rate
#define LOG_FILE_NAME "/system_log.txt" // File name of the log file
#define LOG_DEFAULT_LEVEL TesLight::Logger::LogLevel::INFO // Default log level

// Configuration of the runtime configuration
#define CONFIGURATION_FILE_NAME "/config.tli"
#define CONFIGURATION_FILE_VERSION 3
#define CONFIGURATION_FILE_NAME "/config.tli" // File name of the configuration file
#define CONFIGURATION_FILE_VERSION 4 // Version of the configuration file

// LED and animator configuration
#define LED_NUM_ZONES 8
#define LED_OUTPUT_PINS {13, 17, 14, 21, 15, 22, 16, 25} // Should balance the laod between the regulators well
#define LED_COUNTS {2, 2, 2, 2, 2, 2, 2, 2}
#define LED_DEFAULT_CHANNEL_CURRENT 14
#define ANIMATOR_NUM_CUSTOM_FIELDS 15
#define ANIMATOR_DEFAULT_TYPE 0
#define ANIMATOR_DEFAULT_SPEED 50
#define ANIMATOR_DEFAULT_OFFSET 10
#define ANIMATOR_DEFAULT_BRIGHTNESS 50
#define ANIMATOR_DEFAULT_REVERSE false
#define ANIMATOR_DEFAULT_FADE_SPEED 30
#define LED_NUM_ZONES 8 // Number of LED zones
#define LED_DEFAULT_OUTPUT_PINS {13, 14, 15, 16, 17, 21, 22, 25} // Pin mapping of zones to physical pins
#define LED_DEFAULT_COUNTS {2, 2, 2, 2, 2, 2, 2, 2} // Default number of LEDs for each channel
#define LED_DEFAULT_CHANNEL_CURRENT 14 // Default current per LED channel in mA
#define ANIMATOR_NUM_CUSTOM_FIELDS 15 // Number of custom fields in the LED configuration
#define ANIMATOR_DEFAULT_TYPE 0 // Default animation type
#define ANIMATOR_DEFAULT_SPEED 50 // Default animation speed
#define ANIMATOR_DEFAULT_OFFSET 10 // Default animation offset
#define ANIMATOR_DEFAULT_BRIGHTNESS 50 // Default zone brightness
#define ANIMATOR_DEFAULT_REVERSE false // Default reversal of the animation
#define ANIMATOR_DEFAULT_FADE_SPEED 30 // Default fading speed

// Voltage regulator
#define REGULATOR_POWER_LIMIT 10 // W per regulator
#define REGULATOR_COUNT 2
#define REGULATOR_DEFAULT_VOLTAGE 50 // Voltage x10
#define REGULATOR_ZONE_MAPPING {0, 1, 0, 1, 0, 1, 0, 1} // Maps zone index to regulator number
#define REGULATOR_POWER_LIMIT 12 // W per regulator
#define REGULATOR_COUNT 2 // Number of regulators
#define REGULATOR_DEFAULT_VOLTAGE 50 // Output Voltage x10
#define REGULATOR_ZONE_MAPPING {0, 1, 0, 1, 0, 1, 0, 1} // Maps zone index to regulator number
#define REGULATOR_HIGH_TEMP 70 // Temp in °C where brightness is reduced
#define REGULATOR_CUT_OFF_TEMP 85 // Temp in °C where LEDs are turned off

// Cooling fan
#define FAN_PWM_PIN 27 // Output pin for the fan
#define FAN_PWM_CHANNEL 0 // PWM channel for the fan control
#define FAN_PWM_FREQUENCY 30000 // PWM frequency of the fan in Hz
#define FAN_PWM_RESOLUTION 8 // Resolution of the fan control in bits
#define FAN_PWM_MIN 75 // Minimum PWM value for the fan (stall guard)
#define FAN_PWM_MAX 255 // Maximum PWm value for the fan
#define FAN_TEMP_MIN 60 // Minimum temperature where the fan starts
#define FAN_TEMP_MAX 80 // Maximum temeprature where the fan runs at full speed

// I2C configuration
#define SDA_PIN 32
#define SCL_PIN 33
#define IIC_SDA_PIN 32 // SDA pin
#define IIC_SCL_PIN 33 // SCL pin

// OneWire configuration
#define ONE_WIRE_PIN 26 // Pin of the OneWire bus

// Light sensor configuration
#define LIGHT_SENSOR_PIN 35
#define LIGHT_SENSOR_BUFFER_SIZE 10
#define LIGHT_SENSOR_DEFAULT_MODE TesLight::LightSensor::LightSensorMode::ALWAYS_ON
#define LIGHT_SENSOR_DEFAULT_THRESHOLD 30
#define LIGHT_SENSOR_DEFAULT_MIN 30
#define LIGHT_SENSOR_DEFAULT_MAX 2048
#define LIGHT_SENSOR_DEFAULT_MODE TesLight::LightSensor::LightSensorMode::ALWAYS_ON // Default light sensor mode
#define LIGHT_SENSOR_DEFAULT_THRESHOLD 30 // Threshold for the output to turn on/off
#define LIGHT_SENSOR_DEFAULT_MIN 30 // Minimum value for automatic brightness adjustment
#define LIGHT_SENSOR_DEFAULT_MAX 4095 // Maximum value for automatic brightness adjustment
#define LIGHT_SENSOR_ADC_PIN 35 // Physical pin for the analog voltage sensor
#define IIC_ADDRESS_BH1750 0x23 // I²C Adress of the BH1750 brightness sensor

// Motion sensor configuration
#define MOTION_SENSOR_I2C_ADDRESS 0x68
#define MOTION_SENSOR_BUFFER_SIZE 5
#define IIC_ADDRESS_MPU6050 0x68 // I²C Adress of the MPU6050 motion sensor

// Temperature sensor
#define TEMP_SENSOR_RESOLUTION TesLight::DS18B20::DS18B20Res::DS18B20_12_BIT

// WiFi configuration
#define AP_DEFAULT_SSID "TesLight"
#define AP_DEDAULT_PASSWORD "TesLightPW"
#define AP_DEFAULT_CHANNEL 1
#define AP_DEFAULT_HIDDEN false
#define AP_DEFAULT_MAX_CONN 1
#define WIFI_DEFAULT_SSID ""
#define WIFI_DEFAULT_PASSWORD ""
#define AP_DEFAULT_SSID "TesLight" // Default SSID of the access point
#define AP_DEDAULT_PASSWORD "TesLightPW" // Default password of the access point
#define AP_DEFAULT_CHANNEL 1 // Default channel of the access point
#define AP_DEFAULT_HIDDEN false // Hide or show the SSID by default
#define AP_DEFAULT_MAX_CONN 1 // Default maximum number of connections to the access point
#define WIFI_DEFAULT_SSID "" // Default SSID of a WiFi network
#define WIFI_DEFAULT_PASSWORD "" // Default password of a WiFi network

// Webserver configuration
#define WEB_SERVER_PORT 80
#define WEB_SERVER_STATIC_CONTENT "/web-app/"
#define WEB_SERVER_PORT 80 // Port of the web server
#define WEB_SERVER_STATIC_CONTENT "/web-app/" // Static content location for the web server

// Timer configuration
#define LED_FRAME_TIME 16666
#define LIGHT_SENSOR_CYCLE_TIME 20000
#define MOTION_SENSOR_CYCLE_TIME 20000
#define FPS_CYCLE_TIME 10000000
#define WEB_SERVER_CYCLE_TIME 20000
#define LED_FRAME_TIME 16666 // Cycle time for the LEDs in µs
#define TEMP_CYCLE_TIME 250000 // Cycle time for reading temperatures and run fan controll in µs
#define LIGHT_SENSOR_CYCLE_TIME 20000 // Cycle time for the light sensor in µs
#define MOTION_SENSOR_CYCLE_TIME 20000 // Cycle time for the motion sensor in µs
#define WEB_SERVER_CYCLE_TIME 20000 // Cycle time for the web server to accept conenctions in µs
#define STATUS_CYCLE_TIME 10000000 // Cycle time for printing the current status in µs

// FSEQ configuration
#define FSEQ_DIRECTORY "/fseq"
#define FSEQ_DIRECTORY "/fseq" // Directory for fseq files

// Update configuration
#define UPDATE_DIRECTORY "/update"
#define UPDATE_FILE_NAME "update.tup"
#define UPDATE_DIRECTORY "/update" // Update folder
#define UPDATE_FILE_NAME "update.tup" // Update package file name

#endif
47 changes: 47 additions & 0 deletions mcu/include/hardware/BH1750.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @file BH1750.h
* @author TheRealKasumi
* @brief Contains a class for reading the BH1750 I²C light sensor.
*
* @copyright Copyright (c) 2022
*
*/
#ifndef BH1750_H
#define BH1750_H

#include <stdint.h>
#include <Wire.h>
#include "logging/Logger.h"

namespace TesLight
{
class BH1750
{
public:
enum BH1750Res
{
BH1750_HIGH = 0b00010000,
BH1750_LOW = 0b00010011
};

BH1750(const uint8_t deviceAddress);
BH1750(const uint8_t deviceAddress, const TesLight::BH1750::BH1750Res resolution);
~BH1750();

bool begin();

bool setResolution(const TesLight::BH1750::BH1750Res resolution);
TesLight::BH1750::BH1750Res getResolution();

bool getLux(float &lux);

private:
uint8_t deviceAddress;
TesLight::BH1750::BH1750Res resolution;

bool write(const uint8_t command);
bool read(uint16_t &value);
};
}

#endif
Loading

0 comments on commit f679476

Please sign in to comment.