Skip to content

Commit df9e4cd

Browse files
committed
initial standalone commit
0 parents  commit df9e4cd

33 files changed

+2270
-0
lines changed

examples/FullTest/FullTest.ino

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*TEST RTD AUTOMATION
2+
2020_08_25 SILVIO NAVARETTI
3+
*/
4+
#include <AutomationCarrier.h>
5+
6+
using namespace automation;
7+
8+
// The value of the Rref resistor. Use 430.0 for PT100 and 4300.0 for PT1000
9+
#define RREF 400.0
10+
// The 'nominal' 0-degrees-C resistance of the sensor
11+
// 100.0 for PT100, 1000.0 for PT1000
12+
#define RNOMINAL 100.0
13+
14+
void setup() {
15+
16+
Serial.begin(9600);
17+
Serial.println("Adafruit MAX31865 PT100 Sensor Test!");
18+
19+
temp_probes.selectChannel(0);
20+
temp_probes.rtd.begin(MAX31865_3WIRE); // set to 2WIRE or 4WIRE as necessary
21+
22+
temp_probes.t.begin();
23+
24+
comm_protocols.rs485.begin(9600);
25+
comm_protocols.rs485.enable = 1;
26+
27+
/*
28+
comm_protocols.rs485.half_duplex = 1;
29+
*/
30+
31+
comm_protocols.can.frequency(9600);
32+
33+
analog_in.ch2_in4 = 1;
34+
analog_in.ch0_in2 = 1;
35+
36+
uint16_t raw_voltage = analog_in.read(0);
37+
uint16_t another_raw_voltage = analog_in[1].read_u16();
38+
39+
Serial.println(raw_voltage);
40+
41+
analog_out[1].period_ms(0.3);
42+
analog_out[1].write(0.5f);
43+
}
44+
45+
46+
void loop() {
47+
48+
uint16_t rtd = temp_probes.rtd.readRTD();
49+
50+
Serial.print("RTD value: "); Serial.println(rtd);
51+
float ratio = rtd;
52+
ratio /= 32768;
53+
Serial.print("Ratio = "); Serial.println(ratio, 8);
54+
Serial.print("Resistance = "); Serial.println(RREF * ratio, 8);
55+
Serial.print("Temperature = "); Serial.println(temp_probes.rtd.temperature(RNOMINAL, RREF));
56+
57+
// Check and print any faults
58+
uint8_t fault = temp_probes.rtd.readFault();
59+
if (fault) {
60+
Serial.print("Fault 0x"); Serial.println(fault, HEX);
61+
if (fault & MAX31865_FAULT_HIGHTHRESH) {
62+
Serial.println("RTD High Threshold");
63+
}
64+
if (fault & MAX31865_FAULT_LOWTHRESH) {
65+
Serial.println("RTD Low Threshold");
66+
}
67+
if (fault & MAX31865_FAULT_REFINLOW) {
68+
Serial.println("REFIN- > 0.85 x Bias");
69+
}
70+
if (fault & MAX31865_FAULT_REFINHIGH) {
71+
Serial.println("REFIN- < 0.85 x Bias - FORCE- open");
72+
}
73+
if (fault & MAX31865_FAULT_RTDINLOW) {
74+
Serial.println("RTDIN- < 0.85 x Bias - FORCE- open");
75+
}
76+
if (fault & MAX31865_FAULT_OVUV) {
77+
Serial.println("Under/Over voltage");
78+
}
79+
temp_probes.rtd.clearFault();
80+
}
81+
Serial.println();
82+
delay(1000);
83+
84+
Serial.print("Reference temperature ");
85+
Serial.print(temp_probes.t.readReferenceTemperature());
86+
Serial.println(" °C");
87+
88+
Serial.print("Temperature ");
89+
Serial.print(temp_probes.t.readTemperature());
90+
Serial.println(" °C");
91+
92+
Serial.println();
93+
}

library.properties

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=AutomationCArrier
2+
version=0.0.1
3+
author=Arduino
4+
maintainer=Arduino <info@arduino.cc>
5+
sentence=Arduino Library for the Automation Carrier
6+
paragraph=
7+
category=Communication
8+
url=https://github.com/arduino-libraries/AutomationCarrier
9+
architectures=mbed
10+
includes=AutomationCarrier.h

src/AutomationCarrier.h

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
#ifndef __AUTOMATION_CARRIER_H__
2+
#define __AUTOMATION_CARRIER_H__
3+
4+
#include "utility/Adafruit_MAX31865/Adafruit_MAX31865.h"
5+
#include "utility/Arduino_MKRTHERM/src/MKRTHERM.h"
6+
#include "utility/ArduinoRS485/src/ArduinoRS485.h"
7+
8+
#include "mbed.h"
9+
10+
namespace automation {
11+
12+
class RTDClass {
13+
public:
14+
void setTH() {
15+
rtd_th = 1;
16+
}
17+
void resetTH() {
18+
rtd_th = 0;
19+
}
20+
void selectChannel(int channel) {
21+
for (int i=0; i<3; i++) {
22+
ch_sel[i] = (i == channel ? 1 : 0);
23+
}
24+
}
25+
26+
Adafruit_MAX31865 rtd = Adafruit_MAX31865(PA_6);
27+
THERMClass t = THERMClass(7);
28+
29+
private:
30+
mbed::DigitalOut ch_sel[3] = { mbed::DigitalOut(PA_0), mbed::DigitalOut(PI_4), mbed::DigitalOut(PJ_9) };
31+
mbed::DigitalOut rtd_th = mbed::DigitalOut(PH_9);
32+
};
33+
34+
extern RTDClass temp_probes;
35+
36+
static mbed::CAN _can(PH_13, PB_8);
37+
38+
class COMMClass {
39+
public:
40+
void enableCAN() {
41+
can_disable = 0;
42+
}
43+
void disableCAN() {
44+
can_disable = 1;
45+
}
46+
47+
UART _UART4_ = arduino::UART(PA_0, PI_9, PI_10, PI_13);
48+
mbed::CAN& can = _can;
49+
50+
RS485Class rs485 = RS485Class(_UART4_);
51+
52+
private:
53+
mbed::DigitalOut can_disable = mbed::DigitalOut(PA_13, 0);
54+
55+
56+
};
57+
58+
extern COMMClass comm_protocols;
59+
60+
#define ch0_in1 ch_in[0]
61+
#define ch0_in2 ch_in[1]
62+
#define ch0_in3 ch_in[2]
63+
#define ch0_in4 ch_in[3]
64+
#define ch1_in1 ch_in[4]
65+
#define ch1_in2 ch_in[5]
66+
#define ch1_in3 ch_in[6]
67+
#define ch1_in4 ch_in[7]
68+
#define ch2_in1 ch_in[8]
69+
#define ch2_in2 ch_in[9]
70+
#define ch2_in3 ch_in[10]
71+
#define ch2_in4 ch_in[11]
72+
73+
class AnalogInClass {
74+
public:
75+
uint16_t read(int channel) {
76+
switch (channel) {
77+
case 0:
78+
return in_0.read_u16();
79+
case 1:
80+
return in_1.read_u16();
81+
case 2:
82+
return in_2.read_u16();
83+
default:
84+
break;
85+
}
86+
return 0;
87+
}
88+
89+
mbed::AnalogIn& operator[](int index) {
90+
switch (index) {
91+
case 0:
92+
return in_0;
93+
case 1:
94+
return in_1;
95+
case 2:
96+
return in_2;
97+
}
98+
}
99+
100+
mbed::DigitalOut ch_in[12] = {
101+
mbed::DigitalOut(PD_4), mbed::DigitalOut(PD_5), mbed::DigitalOut(PE_3), mbed::DigitalOut(PG_3),
102+
mbed::DigitalOut(PA_6), mbed::DigitalOut(PH_6), mbed::DigitalOut(PJ_7), mbed::DigitalOut(PH_15),
103+
mbed::DigitalOut(PH_10), mbed::DigitalOut(PA_4), mbed::DigitalOut(PA_8), mbed::DigitalOut(PC_6)
104+
};
105+
106+
private:
107+
mbed::AnalogIn in_0 = mbed::AnalogIn(PC_3C);
108+
mbed::AnalogIn in_1 = mbed::AnalogIn(PA_1C);
109+
mbed::AnalogIn in_2 = mbed::AnalogIn(PC_2C);
110+
};
111+
112+
extern AnalogInClass analog_in;
113+
114+
115+
class AnalogOutClass {
116+
public:
117+
mbed::PwmOut& operator[](int index) {
118+
switch (index) {
119+
case 0:
120+
return out_0;
121+
case 1:
122+
return out_1;
123+
case 2:
124+
return out_2;
125+
}
126+
}
127+
private:
128+
mbed::PwmOut out_0 = mbed::PwmOut(PJ_11);
129+
mbed::PwmOut out_1 = mbed::PwmOut(PG_7);
130+
mbed::PwmOut out_2 = mbed::PwmOut(PC_7);
131+
};
132+
133+
extern AnalogOutClass analog_out;
134+
135+
136+
/*
137+
TODO: writeme
138+
Use QEI library for mbed since it implements index pin
139+
*/
140+
141+
class EncoderClass {
142+
public:
143+
private:
144+
};
145+
146+
extern EncoderClass encoders;
147+
148+
/*
149+
TODO: writeme
150+
using gpio expander class https://www.i2cdevlib.com/devices/tca6424a#source
151+
Ask Giampaolo for proper porting
152+
Expander interrupt is PI_5
153+
prog_latch_retry (AKA TERM ? ) is PH_14
154+
*/
155+
156+
class ProgrammableDIOClass {
157+
public:
158+
private:
159+
};
160+
161+
extern ProgrammableDIOClass programmable_digital_io;
162+
163+
164+
class DigitalOutputsClass {
165+
public:
166+
uint8_t setAll(uint8_t val) {
167+
for (int i = 0; i < 8; i++) {
168+
out[i] = val & 0x1;
169+
val = val >> 1;
170+
}
171+
}
172+
mbed::DigitalOut& operator[](int index) {
173+
return out[index];
174+
}
175+
private:
176+
mbed::DigitalOut out[8] = {
177+
mbed::DigitalOut(PI_6), mbed::DigitalOut(PC_15), mbed::DigitalOut(PG_10), mbed::DigitalOut(PE_2),
178+
mbed::DigitalOut(PI_3), mbed::DigitalOut(PI_2), mbed::DigitalOut(PD_3), mbed::DigitalOut(PA_14)
179+
};
180+
};
181+
182+
extern DigitalOutputsClass digital_outputs;
183+
184+
185+
class DigitalInputsClass {
186+
public:
187+
uint8_t readAll() {
188+
uint8_t val = 0;
189+
for (int i = 0; i < 8; i++) {
190+
val |= (in[i] << i);
191+
}
192+
return val;
193+
}
194+
mbed::DigitalIn& operator[](int index) {
195+
return in[index];
196+
}
197+
private:
198+
mbed::DigitalIn in[8] = {
199+
mbed::DigitalIn(PD_6), mbed::DigitalIn(PD_7), mbed::DigitalIn(PB_14), mbed::DigitalIn(PB_15),
200+
mbed::DigitalIn(PB_3), mbed::DigitalIn(PB_4), mbed::DigitalIn(PB_2), mbed::DigitalIn(PI_7)
201+
};
202+
};
203+
204+
extern DigitalInputsClass digital_inputs;
205+
}
206+
207+
#endif

src/Objects.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "AutomationCarrier.h"
2+
3+
namespace automation {
4+
5+
RTDClass temp_probes;
6+
COMMClass comm_protocols;
7+
AnalogInClass analog_in;
8+
AnalogOutClass analog_out;
9+
EncoderClass encoders;
10+
DigitalOutputsClass digital_outputs;
11+
DigitalInputsClass digital_inputs;
12+
ProgrammableDIOClass programmable_digital_io;
13+
14+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Thank you for opening an issue on an Adafruit Arduino library repository. To
2+
improve the speed of resolution please review the following guidelines and
3+
common troubleshooting steps below before creating the issue:
4+
5+
- **Do not use GitHub issues for troubleshooting projects and issues.** Instead use
6+
the forums at http://forums.adafruit.com to ask questions and troubleshoot why
7+
something isn't working as expected. In many cases the problem is a common issue
8+
that you will more quickly receive help from the forum community. GitHub issues
9+
are meant for known defects in the code. If you don't know if there is a defect
10+
in the code then start with troubleshooting on the forum first.
11+
12+
- **If following a tutorial or guide be sure you didn't miss a step.** Carefully
13+
check all of the steps and commands to run have been followed. Consult the
14+
forum if you're unsure or have questions about steps in a guide/tutorial.
15+
16+
- **For Arduino projects check these very common issues to ensure they don't apply**:
17+
18+
- For uploading sketches or communicating with the board make sure you're using
19+
a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes
20+
very hard to tell the difference between a data and charge cable! Try using the
21+
cable with other devices or swapping to another cable to confirm it is not
22+
the problem.
23+
24+
- **Be sure you are supplying adequate power to the board.** Check the specs of
25+
your board and plug in an external power supply. In many cases just
26+
plugging a board into your computer is not enough to power it and other
27+
peripherals.
28+
29+
- **Double check all soldering joints and connections.** Flakey connections
30+
cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints.
31+
32+
- **Ensure you are using an official Arduino or Adafruit board.** We can't
33+
guarantee a clone board will have the same functionality and work as expected
34+
with this code and don't support them.
35+
36+
If you're sure this issue is a defect in the code and checked the steps above
37+
please fill in the following fields to provide enough troubleshooting information.
38+
You may delete the guideline and text above to just leave the following details:
39+
40+
- Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE**
41+
42+
- Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO
43+
VERSION HERE**
44+
45+
- List the steps to reproduce the problem below (if possible attach a sketch or
46+
copy the sketch code in too): **LIST REPRO STEPS BELOW**

0 commit comments

Comments
 (0)