Skip to content

Commit 8312f30

Browse files
author
jenkie
committed
1 parent cc19710 commit 8312f30

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

Arduino_Pedelec_Controller/Arduino_Pedelec_Controller.ino

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ volatile boolean readtorque=false; //true if torque array has been updated -> r
282282
unsigned long bbs_pausestart=0; //start time of power pause for gear change
283283
#endif
284284

285+
#ifdef SUPPORT_THERMISTOR
286+
float temperature_thermistor=0; //thermistor temperature
287+
#endif
288+
285289
#if (SERIAL_MODE & SERIAL_MODE_MMC) //communicate with mmc-app
286290
String mmc_command="";
287291
byte mmc_value=0;
@@ -544,6 +548,10 @@ loadcell.tare(); //set zero scale. remove any load diring star
544548
loadcell.set_scale(hx711_scale); //apply scaling
545549
#endif
546550

551+
#ifdef SUPPORT_THERMISTOR
552+
pinMode(thermistor_pin,INPUT);
553+
#endif
554+
547555
#ifdef DEBUG_MEMORY_USAGE
548556
Serial.print(MY_F("memFree after setup:"));
549557
Serial.print(memFree());
@@ -975,6 +983,10 @@ if (loadcell.is_ready()) //new conversion result from load cell available
975983
sensors.requestTemperatures(); // read temperature(s) from DS18x20 sensor. Readouts are in sensors.getTempCByIndex(n)
976984
#endif
977985

986+
#ifdef SUPPORT_THERMISTOR
987+
temperature_thermistor=1/(thermistor_t0+thermistor_b*log((10240/analogRead(thermistor_pin)-10)/thermistor_r))-273.15; //calculate thermistor temperature from Steinhart-Hart parameters
988+
#endif
989+
978990
battery_percent_fromcapacity = constrain((1-wh/ curr_capacity)*100,0,100); //battery percent calculation from battery capacity. For voltage-based calculation see above
979991
range=constrain(curr_capacity/wh*km-km,0.0,200.0); //range calculation from battery capacity
980992
wh+=current*(millis()-last_writetime)/3600000.0*voltage; //watthours calculation
@@ -1252,6 +1264,10 @@ void serial_debug(HardwareSerial* localSerial)
12521264
#ifdef SUPPORT_TEMP_SENSOR
12531265
localSerial->print(MY_F(" Temp"));
12541266
localSerial->print(sensors.getTempCByIndex(0),2);
1267+
#endif
1268+
#ifdef SUPPORT_THERMISTOR
1269+
localSerial->print(MY_F(" Temp"));
1270+
localSerial->print(temperature_thermistor,1);
12551271
#endif
12561272
/*
12571273
localSerial->print(MY_F(" TEMP"));

Arduino_Pedelec_Controller/config.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ const byte gear_shift_pin_high_gear = 7; //pin that connects to the high gea
175175
//#define SUPPORT_TEMP_SENSOR //uncomment if you want to use a DS18x20 temperature sensor
176176
const byte temp_pin = A2; //pin connected to Data pin of the DS18x20 temperature Sensor
177177

178+
//#define SUPPORT_THERMISTOR //uncomment if you have thermistor connected
179+
const byte thermistor_pin = A2; //thermistor pin
180+
const float thermistor_t0=0.00335401643; // 1/T0 of thermistor in 1/K
181+
const float thermistor_b=0.00025316455; // 1/beta of thermistor in 1/K
182+
const float thermistor_r=10; // r of thermistor in kOhm
183+
178184
//#define SUPPORT_HX711 //uncomment this if you want to use a load cell with hx711 amplifier
179185
const byte hx711_data=20; //data pin of hx711 sensor
180186
const byte hx711_sck=21; //clock pin of hx711 sensor

tools/compile_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
'SUPPORT_GEAR_SHIFT',
4848
'SUPPORT_MOTOR_SERVO',
4949
'SUPPORT_TEMP_SENSOR',
50+
'SUPPORT_THERMISTOR',
5051
'SUPPORT_HX711',
5152
'DETECT_BROKEN_SPEEDSENSOR',
5253
'USE_EXTERNAL_CURRENT_SENSOR',
@@ -205,6 +206,10 @@ def write_config_h(filename=CONFIG_H,
205206
f.write('\n')
206207
f.write('//Config Options-----------------------------------------------------------------------------------------------------\n')
207208
f.write('const byte temp_pin = A2; //pin connected to Data pin of the DS18x20 temperature Sensor\n')
209+
f.write('const byte thermistor_pin = A2; //thermistor pin\n')
210+
f.write('const float thermistor_t0=0.00335401643; // 1/T0 of thermistor in 1/K\n')
211+
f.write('const float thermistor_b=0.00025316455; // 1/beta of thermistor in 1/K\n')
212+
f.write('const float thermistor_r=10; // r of thermistor in kOhm\n')
208213
f.write('const int pas_tolerance=1; //0... increase to make pas sensor slower but more tolerant against speed changes\n')
209214
f.write('const int throttle_offset=196; //Offset voltage of throttle control when in "0" position (0..1023 = 0..5V)\n')
210215
f.write('const int throttle_max=832; //Offset voltage of throttle control when in "MAX" position (0..1023 = 0..5V)\n')
@@ -476,6 +481,7 @@ def test_max_config_fc2x0(self):
476481
'SUPPORT_BATTERY_CHARGE_COUNTER',
477482
'SUPPORT_GEAR_SHIFT',
478483
'SUPPORT_TEMP_SENSOR',
484+
'SUPPORT_THERMISTOR',
479485
'SUPPORT_HX711',
480486
'DETECT_BROKEN_SPEEDSENSOR'
481487
]

0 commit comments

Comments
 (0)