Commit b504883b authored by Patrick's avatar Patrick

call RP.begin before Serial.begin, plus intro comment texts

parent 9ac8e8d5
#include <Wire.h>
#include <MCP342x.h>
/*
Read a TMP36 sensor from MCP3428, channel 3
*/
#define BAUD 115200
// 0x68 is the default address for all MCP342x devices
// on Red-Peg, the MCP3428 address is set to 0x6F
uint8_t address = 0x6F;
MCP342x adc = MCP342x(address);
void setup(void)
{
Serial.begin(BAUD);
Serial.println("starting temp_mon");
Wire.begin();
// Reset devices
MCP342x::generalCallReset();
delay(1); // MC342x needs 300us to settle, wait 1ms
// Check device present
Wire.requestFrom(address, (uint8_t)1);
if (!Wire.available()) {
Serial.print("No device found at address ");
Serial.println(address, HEX);
while (1)
;
} else {
Serial.println("MCP3248 found");
}
}
void loop(void)
{
long value = 0;
MCP342x::Config status;
// Initiate a conversion; convertAndRead() will wait until it can be read
uint8_t err = adc.convertAndRead(MCP342x::channel3, MCP342x::oneShot,
MCP342x::resolution16, MCP342x::gain1,
1000000, value, status);
if (err) {
Serial.print("Convert error: ");
Serial.println(err);
}
else {
float voltage = value * (2.0 / 32575.0);
float temp = (voltage-0.5) * 100;
Serial.print("Value: ");
Serial.print(value);
Serial.print(", ");
Serial.print(voltage);
Serial.print("V, ");
Serial.print(temp);
Serial.print(" degC");
Serial.println();
}
delay(1000);
}
/* sensor_blink
*
* toggle the sensor active pin on Red-Peg board,
* without using the red_peg library
*
*/
#define SENSOR_ACTIVE_PIN 6
#define BAUD 115200
// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(BAUD);
Serial.println(F("start sensor_blink"));
......@@ -9,10 +15,9 @@ void setup() {
pinMode(SENSOR_ACTIVE_PIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(SENSOR_ACTIVE_PIN, HIGH);
delay(1000); // wait for a second
delay(1000);
digitalWrite(SENSOR_ACTIVE_PIN, LOW);
delay(1000); // wait for a second
delay(1000);
}
/* rp_ma4_20
*
* Take readings from the 4–20mA sensor port and show the
* ADC reading, mA value and equivalent 0–7000mm level reading
*
*/
#include <red_peg.h>
red_peg RP;
void setup() {
RP.begin();
delay(100);
Serial.begin(BAUD);
Serial.println("starting rp_ma4_20");
RP.begin();
}
void loop() {
......@@ -13,7 +21,7 @@ void loop() {
delay(100);
t_SensorData depth = RP.get(MA4_20);
RP.sensorsOff();
if (depth.sensor == MA4_20) {
Serial.print("Value: ");
Serial.print(depth.reading);
......@@ -23,8 +31,6 @@ void loop() {
Serial.print(RP.level(depth, 7000L));
Serial.print(" mm");
Serial.println();
} else {
Serial.println("no return from ADC");
delay(1000);
}
delay(1000);
}
/*
/* rp_maxbotix
*
* Reading the MB 7060 sensor to give distance readings
*
* It is recommended to providing an external power supply
* as the maxbotix ultrasound sensors can draw more than
* the 0.5A that a USB port is able to supply
*
* Powering from USB only may lead to some crashes/restarts
* because of the current draw
*
*
*/
#include <red_peg.h>
red_peg RP;
void setup() {
delay(2000);
delay(1000);
RP.begin();
delay(100);
Serial.begin(BAUD);
Serial.println("starting rp_maxbotix");
......@@ -28,7 +24,7 @@ void loop() {
delay(500);
t_SensorData depth = RP.get(ANA);
RP.sensorsOff();
if (depth.sensor == ANA) {
RP.print_data(depth);
Serial.print("Value: ");
......
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
/* rp_rtc_ds1307
*
* Read the date and time from the Red-Peg onboard RTC
* report over serial.
*
*/
#include <red_peg.h>
red_peg RP;
void setup () {
Serial.begin(115200);
Serial.println(F("start rp_rtc_ds1307"));
RP.begin();
RP.sensorsOn();
delay(100);
Serial.begin(BAUD);
Serial.println(F("start rp_rtc_ds1307"));
}
void loop () {
......@@ -29,7 +34,7 @@ void loop () {
Serial.print("Z");
Serial.println();
} else {
Serial.println(F("no RTC message received. \nLast message is:"));
Serial.println(F("no RTC message received. \r\nLast message is:"));
RP.print_data(the_time);
}
delay(10000);
......
/* rp_sd_logger
*
* Record the TMP36 sensor values to the Red-Peg shield onboard
* SD card under the file: readings.csv
*
*/
#include <SPI.h>
#include <SdFat.h>
SdFat SD;
......@@ -7,10 +14,11 @@ red_peg RP;
void setup()
{
RP.begin();
delay(100);
// Open serial communications and wait for port to open:
Serial.begin(BAUD);
Serial.println("starting rp_sd_logger");
RP.begin();
Serial.print("Initializing SD card...");
pinMode(10, OUTPUT);
......@@ -54,10 +62,10 @@ void loop()
myFile.print(RP.degC(temp));
// and a new line
myFile.println();
// close the file:
myFile.close();
// Then print what we sent to the Serial port
RP.print_data(temp);
Serial.println("done.");
......@@ -67,5 +75,3 @@ void loop()
}
}
}
/* rp_sensor_active
*
* toggles the sensor power and slave microcontroller
* on and off every second
* if you attach an LED + resistor across the
* 0–5V port, it will light when the port powers on
*/
#include <red_peg.h>
red_peg RP;
// the setup function runs once when you press reset or power the board
void setup() {
RP.begin();
delay(100);
Serial.begin(BAUD);
Serial.println(F("start rp_sensor_active"));
RP.begin();
}
// the loop function runs over and over again forever
void loop() {
RP.sensorsOn();
delay(1000); // wait for a second
Serial.print("ON...");
delay(1000);
RP.sensorsOff();
delay(1000); // wait for a second
Serial.println("OFF");
delay(1000);
}
/* rp_temp_mon
*
* Take a reading from a TMP36 sensor in the 0–2V port
* on the red peg board and report it to the Serial monitor
*
*/
#include <red_peg.h>
red_peg RP;
void setup() {
Serial.begin(BAUD);
RP.begin();
RP.sensorsOn();
delay(100);
Serial.begin(BAUD);
Serial.println(F("start rp_temp_mon"));
}
void loop() {
......
/* set_the_time
*
* Helper sketch to set a custom time on a DS1307
* (such as the one on the Red-Peg board).
* Type the date and time into the serial monitor, in the
* format: T YYYY MM DD hh mm ss
* Will then report the current time every 10 seconds
*
* Requires the Adafruit RTClib library
*
*/
#include <Wire.h>
#include <RTClib.h>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment