Skip to content

Commit eec1e9a

Browse files
committed
ntc and pcf8591 mods
1 parent 7ea385c commit eec1e9a

File tree

5 files changed

+92
-41
lines changed

5 files changed

+92
-41
lines changed

max31855.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <ktypelinear.h>
77
// #include <quickstats.h> // @todo test quickstats, add child class for container
88
// #include <Statistics.h> // https://github.com/provideyourown/statistics
9-
#include <ntc_multi.h>
109
#include <Average.h>
1110
#include <number_format.h>
1211

ntc.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* https://en.wikipedia.org/wiki/Thermistor#Steinhart.E2.80.93Hart_equation *
1313
*
1414
* See the example for more information. *
15-
*
15+
*
1616
* Example of use with panStamp:
1717
* https://github.com/panStamp/panstamp/wiki/Temperature-measurement-with-cheap-NTC's
1818
*/
@@ -27,7 +27,7 @@ int rt = 330000/V - 320000;
2727

2828
// Thermistor object
2929
THERMISTOR thermistor(NTC_PIN, // Analog pin
30-
10000, // Nominal resistance at 25 ºC
30+
100000, // Nominal resistance at 25 ºC
3131
3950, // thermistor's beta coefficient
3232
10000); // Value of the series resistor
3333

@@ -49,6 +49,10 @@ float get_ntc(){
4949
return ntc_temp;
5050
}
5151

52+
void calc_ntc(int value){
53+
ntc_temp = thermistor.read(value);
54+
}
55+
5256
/**
5357
* loop
5458
*
@@ -64,9 +68,9 @@ void read_ntc()
6468
}
6569

6670
void printNTC(){
67-
read_ntc();
71+
// read_ntc();
6872
float tempf = (((ntc_temp/10)*1.8)+32);
69-
Serial.println("[NTC]: " + (String)(get_ntc()/10) + "ºC " + tempf + "ºF");
73+
Logger.println("[NTC]: " + (String)(get_ntc()/10) + "ºC " + tempf + "ºF");
7074
}
7175

7276
#endif

ntc_multi.h

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef ntc_h
2-
#define ntc_h
1+
#ifndef ntc_multi_h
2+
#define ntc_multi_h
33

44
#include "thermistor.h"
55
/**
@@ -34,25 +34,30 @@ int rt = 330000/V - 320000;
3434
// 3950, // thermistor's beta coefficient
3535
// 10000); // Value of the series resistor
3636

37-
uint16_t resist = 100000;
37+
uint16_t resist = 100000;
3838
uint16_t ntcnominal = 100000;
39-
uint16_t betaco = 3950;
40-
bool lowside = true;
39+
uint16_t betaco = 3950;
40+
41+
// Does not properly compensate for non balanced reisstance
4142

4243
#ifdef local_thermistor_h
44+
bool lowside = true;
4345
THERMISTOR ntc(NTC_PIN,ntcnominal,betaco,resist,lowside);
4446
THERMISTOR ntcB(NTC_BPIN,ntcnominal,betaco,resist,!lowside);
4547
THERMISTOR ntcC(NTC_CPIN,ntcnominal,betaco,resist,lowside);
48+
THERMISTOR ntcD(NTC_CPIN,ntcnominal,betaco,resist,lowside);
4649
#else
47-
THERMISTOR ntc(NTC_PIN,ntcnominal,betaco,resist);
50+
THERMISTOR ntc(NTC_PIN ,ntcnominal,betaco,resist);
4851
THERMISTOR ntcB(NTC_BPIN,ntcnominal,betaco,resist);
4952
THERMISTOR ntcC(NTC_CPIN,ntcnominal,betaco,resist);
53+
THERMISTOR ntcD(NTC_CPIN,ntcnominal,betaco,resist);
5054
#endif
5155

5256
// Global temperature reading
5357
float ntc_temp;
5458
float ntc_temp_b;
5559
float ntc_temp_c;
60+
float ntc_temp_d;
5661

5762
/**
5863
* setup
@@ -75,6 +80,11 @@ float get_ntc_B(){
7580
float get_ntc_C(){
7681
return ntc_temp_c;
7782
}
83+
84+
float get_ntc_D(){
85+
return ntc_temp_d;
86+
}
87+
7888
/**
7989
* loop
8090
*
@@ -85,16 +95,41 @@ void read_ntc()
8595
ntc_temp = ntc.read(); // Read temperature
8696
ntc_temp_b = ntcB.read();
8797
ntc_temp_c = ntcC.read();
98+
ntc_temp_d = ntcD.read();
8899
// Serial.print("Temp in 1/10 ºC : ");
89100
// Serial.println(ntc_temp);
90101
// Serial.print("Temp in ºF : ");
91102
// Serial.println((((ntc_temp/10)*1.8)+32));
92103
}
93104

94105
void printNTC(){
95-
read_ntc();
96-
float tempf = (((ntc_temp/10)*1.8)+32);
97-
Serial.println("[NTC]: " + (String)(get_ntc()/10) + "ºC " + tempf + "ºF");
106+
// read_ntc();
107+
float tempf;
108+
tempf = (((ntc_temp/10)*1.8)+32);
109+
Serial.println("[NTC]: " + (String)(get_ntc()/10) + "ºC " + tempf + "ºF");
110+
111+
tempf = (((ntc_temp_b/10)*1.8)+32);
112+
Serial.println("[NTC]: " + (String)(get_ntc_B()/10) + "ºC " + tempf + "ºF");
113+
114+
tempf = (((ntc_temp_c/10)*1.8)+32);
115+
Serial.println("[NTC]: " + (String)(get_ntc_C()/10) + "ºC " + tempf + "ºF");
116+
117+
tempf = (((ntc_temp_d/10)*1.8)+32);
118+
Serial.println("[NTC]: " + (String)(get_ntc_D()/10) + "ºC " + tempf + "ºF");
119+
}
120+
121+
122+
void calc_ntc(int value){
123+
ntc_temp = ntc.read(value);
124+
}
125+
void calc_ntc_B(int value){
126+
ntc_temp_b = ntcB.read(value);
127+
}
128+
void calc_ntc_C(int value){
129+
ntc_temp_c = ntcC.read(value);
130+
}
131+
void calc_ntc_D(int value){
132+
ntc_temp_d = ntcD.read(value);
98133
}
99134

100135
#endif

ntc_test.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <ntc_multi.h>
2+
3+
void setup(){
4+
5+
}
6+
7+
void loop(){
8+
printNTC();
9+
calc_ntc(get_PCF8591(0)*16);
10+
calc_ntc_B(get_PCF8591(1)*16);
11+
calc_ntc_C(get_PCF8591(2)*16);
12+
calc_ntc_D(get_PCF8591(3)*16);
13+
Serial.println(String(get_ntc()/10));
14+
Serial.println(String(get_ntc_B()/10));
15+
Serial.println(String(get_ntc_C()/10));
16+
Serial.println(String(get_ntc_D()/10));
17+
}

sense_env.h

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ float get_env(uint8_t channel = 0){
116116

117117
#ifdef PCF8591
118118
#include <Adafruit_PCF8591.h>
119+
120+
// TwoWire Wire_B = TwoWire();
121+
// Wire_B.setClock(100000);
122+
// Wire_B.setClockStretchLimit();
123+
// adafruit_i2c bool setSpeed(uint32_t desiredclk);
124+
119125
// Make sure that this is set to the value in volts of VCC
120126
#define ADC_REFERENCE_VOLTAGE 5.0
121127
Adafruit_PCF8591 pcf = Adafruit_PCF8591();
@@ -136,33 +142,8 @@ float int_to_volts(uint16_t dac_value, uint8_t bits, float logic_level) {
136142
return (((float)dac_value / ((1 << bits) - 1)) * logic_level);
137143
}
138144

139-
void print_PCF8591(){
140-
pcf.analogWrite(random(255));
141-
// Make a triangle wave on the DAC output
142-
// pcf.analogWrite(dac_counter++);
143-
Logger.print((pcf.analogRead(0)));
144-
Logger.print(", ");
145-
Logger.print((pcf.analogRead(1)));
146-
Logger.print(", ");
147-
Logger.print((pcf.analogRead(2)));
148-
Logger.print(", ");
149-
Logger.print((pcf.analogRead(3)));
150-
Logger.print("");
151-
Logger.println("");
152-
153-
Logger.print(int_to_volts(pcf.analogRead(0), 8, ADC_REFERENCE_VOLTAGE));
154-
Logger.print("V, ");
155-
Logger.print(int_to_volts(pcf.analogRead(1), 8, ADC_REFERENCE_VOLTAGE));
156-
Logger.print("V, ");
157-
Logger.print(int_to_volts(pcf.analogRead(2), 8, ADC_REFERENCE_VOLTAGE));
158-
Logger.print("V, ");
159-
Logger.print(int_to_volts(pcf.analogRead(3), 8, ADC_REFERENCE_VOLTAGE));
160-
Logger.print("V");
161-
Logger.println("");
162-
}
163-
164-
165145
float get_PCF8591(uint8_t channel = 0, bool volts=false){
146+
Wire.setClock(100000L);
166147
// print_env();
167148
if(volts){
168149
if(channel == 0) return int_to_volts(pcf.analogRead(0), 8, ADC_REFERENCE_VOLTAGE);
@@ -176,6 +157,19 @@ float get_PCF8591(uint8_t channel = 0, bool volts=false){
176157
if(channel == 2) return pcf.analogRead(2);
177158
if(channel == 3) return pcf.analogRead(3);
178159
}
160+
Wire.setClock(400000L);
161+
}
162+
163+
void print_PCF8591(){
164+
pcf.analogWrite(random(128)+128);
165+
for(int i=0;i<4;i++){
166+
Logger.print(get_PCF8591(i));
167+
}
168+
Logger.println("");
169+
for(int i=0;i<4;i++){
170+
Logger.print(get_PCF8591(i,true));
171+
}
172+
Logger.println("");
179173
}
180174

181175
#endif
@@ -293,7 +287,7 @@ void print_mpu6050(){
293287
}
294288

295289
float get_mpu6050(uint8_t channel = 0){
296-
print_mpu6050();
290+
// print_mpu6050();
297291
sensors_event_t a, g, temp;
298292
mpu.getEvent(&a, &g, &temp);
299293
// accel m/s^2
@@ -809,4 +803,6 @@ float getVoltage(){
809803
}
810804
#endif
811805

806+
807+
812808
#endif

0 commit comments

Comments
 (0)