From 0a591d3dd2c32675c9bbb78a9910e886620f44d9 Mon Sep 17 00:00:00 2001 From: Ricardo Date: Mon, 10 Dec 2018 08:01:09 +0000 Subject: [PATCH] Added firmware testing examples. --- .../ProtoIOsArduinoTester_1/Makefile | 12 + .../ProtoIOsArduinoTester.ino | 305 ++++++++++++++++++ .../ProtoIOsArduinoTester_1/pitches.h | 94 ++++++ .../ProtoIOsArduinoTester_20/Makefile | 12 + .../ProtoIOsArduinoTester_20.ino | 296 +++++++++++++++++ .../ProtoIOsArduinoTester_20/pitches.h | 94 ++++++ .../ProtoIOsArduinoTester_20_another/Makefile | 12 + .../ProtoIOsArduinoTester_20.ino | 296 +++++++++++++++++ .../pitches.h | 94 ++++++ 9 files changed, 1215 insertions(+) create mode 100644 ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_1/Makefile create mode 100644 ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_1/ProtoIOsArduinoTester.ino create mode 100644 ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_1/pitches.h create mode 100644 ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_20/Makefile create mode 100644 ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_20/ProtoIOsArduinoTester_20.ino create mode 100644 ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_20/pitches.h create mode 100644 ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_20_another/Makefile create mode 100644 ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_20_another/ProtoIOsArduinoTester_20.ino create mode 100644 ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_20_another/pitches.h diff --git a/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_1/Makefile b/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_1/Makefile new file mode 100644 index 0000000..f34a17e --- /dev/null +++ b/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_1/Makefile @@ -0,0 +1,12 @@ +# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile + +BOARD_TAG = uno +BOARD_SUB = 8MHzatmega328 +USER_LIB_PATH += /home/ricardo/Arduino/libraries +ARDUINO_LIBS += OneWire + + ARDUINO_DIR = /home/ricardo/Installs/arduino-1.8.7 +MONITOR_PORT = /dev/ttyACM3 +-include /usr/share/arduino/Arduino.mk +-include /home/ricardo/Installs/Arduino-Makefile-1.6.0/Arduino.mk + diff --git a/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_1/ProtoIOsArduinoTester.ino b/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_1/ProtoIOsArduinoTester.ino new file mode 100644 index 0000000..0916362 --- /dev/null +++ b/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_1/ProtoIOsArduinoTester.ino @@ -0,0 +1,305 @@ +/* + PROTO I/Os arduino PCB TESTER. + This code tests all the devices in the PROTO I/Os arduino V1.0 PCB shield. + + Four buttons, buttons 3 and 4 have melodys. + Buttons 1 and 2 switch between a light + sequence on the board LEDs, or outputs the temperature read + by (DS18S20, DS18B20, DS1822) has a binary value on to the LEDs. + + + By Jony Silva, www.electropepper.org , 20/4/2014 V1.0 + */ +#include "pitches.h" +#include + +#define ON 1 +#define OFF 0 +#define BUTTON_1 8 +#define BUTTON_2 9 +#define BUTTON_3 10 +#define BUTTON_4 11 +#define BUZZ 13 // Buzzer is connected to digital output 13. +OneWire ds(12); // The DS18S20 is on digital output 12 + + +// Global variables ----------------------------------------------------------------------- + +// Initialize an array with all 8 leds and give them the corresponding +// digital number. +const char led[8] = {0,1,2,3,4,5,6,7}; +char state = ON; // This tells us if the light is ON or OFF +char next = -1; // This indicates which LED we are on, in this case all off +char dir = 'R'; // The direction where the light is going next, R for right, L for left +char mode = 'C'; // The mode for the LEDs, C for chaser, T for temperature +//------------------------------------------------------------------------------------------ + + + +// Function declarations ----------------------------------------------------------------- +void blinker (void); // Rotates the LEDs +void buttons (void); // Reads the buttons +void melody_1 (void); // Calls for melody one +void melody_2 (void); // Calls for melody two +void temperature_read (void); // Reads temperature and displays in binary to the LEDs +//----------------------------------------------------------------------------------------- + + + +// Melodys -------------------------------------------------------------------------------- +//---------------- MELODY ONE ------------------------------------------------ +// Notes in the melody: +int melody1[] = {NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4}; +// Note durations: 4 = quarter note, 8 = eighth note, etc.: +int noteDurations1[] = {4,8,8,4,4,4,4,4}; + + +//---------------- MELODY TWO ------------------------------------------------ +// Notes in the melody: +int melody2[] = {NOTE_C4, NOTE_C4, NOTE_D4, NOTE_C4, NOTE_F4, NOTE_E4, + NOTE_C4, NOTE_C4, NOTE_D4, NOTE_C4, NOTE_G4, NOTE_F4, + NOTE_C4, NOTE_C4, NOTE_C5, NOTE_A4, NOTE_F4, NOTE_E4, NOTE_D4, + NOTE_AS4, NOTE_AS4, NOTE_A4, NOTE_F4, NOTE_G4, NOTE_F4}; +// Note durations: 4 = quarter note, 8 = eighth note, etc.: +int noteDurations2[] = {6, 6, 3, 3, 3, 3, + 6, 6, 3, 3, 3, 3, + 6, 6, 3, 3, 3, 3, 3, + 6, 6, 3, 3, 3, 3}; +//----------------------------------------------------------------------------------------- + + + +// Setup the system ------------------------------------------------------------- +void setup() +{ + + // Initialize all 8 digital I/O pins as outputs. + for (int i = 0; i<8; i++) { + pinMode(led[i], OUTPUT); + } + + // Initialize all 4 Switches as inputs. + for (int i = 8; i<=11; i++) { + pinMode(i, INPUT); + } + + // Initialize Buzzer as output. + pinMode(BUZZ, OUTPUT); + + + // initialize timer1 --------------------------------------- + noInterrupts(); // disable all interrupts + TCCR1A = 0; + TCCR1B = 0; + TCNT1 = 0; + + OCR1A = 9000; // Load value to compare + TCCR1B |= (1 << WGM12); // CTC mode + TCCR1B |= (1 << CS10); // 64 prescaler + TCCR1B |= (1 << CS11); // + TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt + interrupts(); // enable all interrupts + // ---------------------------------------------------------- + +} +//--------------------------------------------------------------------------------- + + +// Timer compare interrupt service routine -------------------------- +ISR(TIMER1_COMPA_vect) // Here we chose between the blinker sequence +{ // or to show the temperature on the LEDs + if (mode == 'C') { + blinker(); + } + else { + temperature_read(); + } +} +// ------------------------------------------------------------------- + + +// Main routine ----------------------------------- +void loop() +{ + // Turn off all digital I/Os, just to make sure + for (int i = 0; i<14; i++) { + digitalWrite(i, LOW); + } + + while(1) + { + buttons(); // Forever check which button was pressed + } +} +// ------------------------------------------------- + +void buttons (void) { + + // If button 1 was pressed change the register mode to 'C' + // this will start the LED light sequence + if (!digitalRead(BUTTON_1)) { + mode = 'C'; + } + + // If button 2 was pressed change the register mode to 'T' + // this will start temperature reading + if (!digitalRead(BUTTON_2)) { + mode = 'T'; + } + + // If button 3 was pressed call the funtion for melody 2 + if (!digitalRead(BUTTON_3)) { + melody_2(); + while (!digitalRead(BUTTON_3)); // Check if button still pressed do nothing + } + + // If button 4 was pressed call the funtion for melody 1 + if (!digitalRead(BUTTON_4)) { + melody_1(); + } + while (!digitalRead(BUTTON_4)); // Check if button still pressed do nothing + } + + +void blinker (void) +{ + if (next == 7 && dir == 'R') { // If next LED is 7 and its rotating right + dir = 'L'; // then set direction register (dir) to L left + } + else if (next == 0 && dir == 'L') { // If next LED is 0 and its rotating left + dir = 'R'; // then set direction register (dir) to R right + } + + + if (state == OFF) { // If light state is OFF + state = ON; // change light state to ON + } + else { // If light state is ON + digitalWrite(next, LOW); // turn off next LED + state = OFF; // change light state to OFF + if (dir == 'R') { // If dir is set to 'R' right + next++; // increment next + } + else { // if dir is set to 'L' left + next--; // decrement next + } + digitalWrite(next, HIGH); // and turn ON next LED + } +} + + +void melody_1 (void) // The following code and melody was taken +{ // from : http://arduino.cc/en/Tutorial/tone + // iterate over the notes of the melody: + for (int thisNote = 0; thisNote < BUZZ; thisNote++) { + + // to calculate the note duration, take one second + // divided by the note type. + //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. + int noteDuration = 500/noteDurations1[thisNote]; + tone(BUZZ, melody1[thisNote],noteDuration); + + // to distinguish the notes, set a minimum time between them. + // the note's duration + 30% seems to work well: + int pauseBetweenNotes = noteDuration * 1.80; // originally 1.30 + delay(pauseBetweenNotes); + // stop the tone playing: + noTone(BUZZ); + } + noTone(BUZZ); +} + +void melody_2 (void) // The following code and melody was taken +{ // from : http://arduino.cc/en/Tutorial/tone + // iterate over the notes of the melody: + for (int thisNote = 0; thisNote < BUZZ; thisNote++) { + + // to calculate the note duration, take one second + // divided by the note type. + //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. + int noteDuration = 500/noteDurations2[thisNote]; + tone(BUZZ, melody2[thisNote],noteDuration); + + // to distinguish the notes, set a minimum time between them. + // the note's duration + 30% seems to work well: + int pauseBetweenNotes = noteDuration * 1.30; // originally 1.30 + delay(pauseBetweenNotes); + // stop the tone playing: + noTone(BUZZ); + } + noTone(BUZZ); +} + +void temperature_read (void) +{ + // This routine was directly take from the OneWire examples + // library, please refer to : http://playground.arduino.cc/Learning/OneWire + // and : http://www.pjrc.com/teensy/td_libs_OneWire.html + + byte i; + byte present = 0; + byte type_s; + byte data[12]; + byte addr[8]; + + + if ( !ds.search(addr)) { + ds.reset_search(); + return; + } + + if (OneWire::crc8(addr, 7) != addr[7]) { + return; + } + + // the first ROM byte indicates which chip + switch (addr[0]) { + case 0x10: + type_s = 1; + break; + case 0x28: + type_s = 0; + break; + case 0x22: + type_s = 0; + break; + default: + return; + } + + ds.reset(); + ds.select(addr); + ds.write(0x44, 1); // start conversion, with parasite power on at the end + + // we might do a ds.depower() here, but the reset will take care of it. + present = ds.reset(); + ds.select(addr); + ds.write(0xBE); // Read Scratchpad + + for ( i = 0; i < 9; i++) { // we need 9 bytes + data[i] = ds.read(); + } + + // Convert the data to actual temperature + // because the result is a 16 bit signed integer, it should + // be stored to an "int16_t" type, which is always 16 bits + // even when compiled on a 32 bit processor. + int16_t raw = (data[1] << 8) | data[0]; + if (type_s) { + raw = raw << 3; // 9 bit resolution default + if (data[7] == 0x10) { + // "count remain" gives full 12 bit resolution + raw = (raw & 0xFFF0) + 12 - data[6]; + } + } else { + byte cfg = (data[4] & 0x60); + // at lower res, the low bits are undefined, so let's zero them + if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms + else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms + else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms + //// default is 12 bit resolution, 750 ms conversion time + } + raw = raw / 16; + PORTD = raw; +} + diff --git a/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_1/pitches.h b/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_1/pitches.h new file mode 100644 index 0000000..362aac8 --- /dev/null +++ b/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_1/pitches.h @@ -0,0 +1,94 @@ +/************************************************* + * Public Constants + *************************************************/ + +#define NOTE_B0 31 +#define NOTE_C1 33 +#define NOTE_CS1 35 +#define NOTE_D1 37 +#define NOTE_DS1 39 +#define NOTE_E1 41 +#define NOTE_F1 44 +#define NOTE_FS1 46 +#define NOTE_G1 49 +#define NOTE_GS1 52 +#define NOTE_A1 55 +#define NOTE_AS1 58 +#define NOTE_B1 62 +#define NOTE_C2 65 +#define NOTE_CS2 69 +#define NOTE_D2 73 +#define NOTE_DS2 78 +#define NOTE_E2 82 +#define NOTE_F2 87 +#define NOTE_FS2 93 +#define NOTE_G2 98 +#define NOTE_GS2 104 +#define NOTE_A2 110 +#define NOTE_AS2 117 +#define NOTE_B2 123 +#define NOTE_C3 131 +#define NOTE_CS3 139 +#define NOTE_D3 147 +#define NOTE_DS3 156 +#define NOTE_E3 165 +#define NOTE_F3 175 +#define NOTE_FS3 185 +#define NOTE_G3 196 +#define NOTE_GS3 208 +#define NOTE_A3 220 +#define NOTE_AS3 233 +#define NOTE_B3 247 +#define NOTE_C4 262 +#define NOTE_CS4 277 +#define NOTE_D4 294 +#define NOTE_DS4 311 +#define NOTE_E4 330 +#define NOTE_F4 349 +#define NOTE_FS4 370 +#define NOTE_G4 392 +#define NOTE_GS4 415 +#define NOTE_A4 440 +#define NOTE_AS4 466 +#define NOTE_B4 494 +#define NOTE_C5 523 +#define NOTE_CS5 554 +#define NOTE_D5 587 +#define NOTE_DS5 622 +#define NOTE_E5 659 +#define NOTE_F5 698 +#define NOTE_FS5 740 +#define NOTE_G5 784 +#define NOTE_GS5 831 +#define NOTE_A5 880 +#define NOTE_AS5 932 +#define NOTE_B5 988 +#define NOTE_C6 1047 +#define NOTE_CS6 1109 +#define NOTE_D6 1175 +#define NOTE_DS6 1245 +#define NOTE_E6 1319 +#define NOTE_F6 1397 +#define NOTE_FS6 1480 +#define NOTE_G6 1568 +#define NOTE_GS6 1661 +#define NOTE_A6 1760 +#define NOTE_AS6 1865 +#define NOTE_B6 1976 +#define NOTE_C7 2093 +#define NOTE_CS7 2217 +#define NOTE_D7 2349 +#define NOTE_DS7 2489 +#define NOTE_E7 2637 +#define NOTE_F7 2794 +#define NOTE_FS7 2960 +#define NOTE_G7 3136 +#define NOTE_GS7 3322 +#define NOTE_A7 3520 +#define NOTE_AS7 3729 +#define NOTE_B7 3951 +#define NOTE_C8 4186 +#define NOTE_CS8 4435 +#define NOTE_D8 4699 +#define NOTE_DS8 4978 + diff --git a/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_20/Makefile b/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_20/Makefile new file mode 100644 index 0000000..f34a17e --- /dev/null +++ b/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_20/Makefile @@ -0,0 +1,12 @@ +# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile + +BOARD_TAG = uno +BOARD_SUB = 8MHzatmega328 +USER_LIB_PATH += /home/ricardo/Arduino/libraries +ARDUINO_LIBS += OneWire + + ARDUINO_DIR = /home/ricardo/Installs/arduino-1.8.7 +MONITOR_PORT = /dev/ttyACM3 +-include /usr/share/arduino/Arduino.mk +-include /home/ricardo/Installs/Arduino-Makefile-1.6.0/Arduino.mk + diff --git a/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_20/ProtoIOsArduinoTester_20.ino b/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_20/ProtoIOsArduinoTester_20.ino new file mode 100644 index 0000000..28e176f --- /dev/null +++ b/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_20/ProtoIOsArduinoTester_20.ino @@ -0,0 +1,296 @@ +/* + PROTO I/Os arduino PCB TESTER. + This code tests all the devices in the PROTO I/Os arduino V1.0 PCB shield. + + Four buttons, buttons 3 and 4 have melodys. + Buttons 1 and 2 switch between a light + sequence on the board LEDs, or outputs the temperature read + by (DS18S20, DS18B20, DS1822) has a binary value on to the LEDs. + + + By Jony Silva, www.electropepper.org , 01/12/2015 V1.0 + */ +#include "pitches.h" +#include + + +#define ON 1 +#define OFF 0 +#define BUTTON_1 8 +#define BUTTON_2 9 +#define BUTTON_3 10 +#define BUTTON_4 11 +#define BUZZ 13 // Buzzer is connected to digital output 13. +OneWire ds(12); // The DS18S20 is on digital output 12 + + +// Global variables ----------------------------------------------------------------------- +const int rot = A4; // Analog input pin to rotate leds +const int vol = A5; // Analog input pin to simulate volume +const char led[8] = {0,1,2,3,4,5,6,7}; // Start array with all 8 leds corresponding digital + // number +int sensorValue = 0; // value read from the pot +char mode = 'V'; // The mode for: 'V' voltage, 'R' rotate, 'T' temperature +//------------------------------------------------------------------------------------------ + + +// Function declarations ----------------------------------------------------------------------- +void VolumeLEDS (void); // Reads POT on A5, shows volume simulation acording to the value +void RotateLEDS (void); // Reads POT on A4, rotates the leds acording to the value +void melody (void); // Calls for melody one +void temperature_read (void); // Reads temperature and displays it in binary to the LEDs +//---------------------------------------------------------------------------------------------- + + +//---------------- MELODY --------------------------------------------------------------- +// Notes in the melody: +int melody1[] = {NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4}; +// Note durations: 4 = quarter note, 8 = eighth note, etc.: +int noteDurations1[] = {4,8,8,4,4,4,4,4}; +//----------------------------------------------------------------------------------------- + + + +void setup() { + + // Initialize all 8 digital I/O pins as outputs. + for (int i = 0; i<8; i++) { + pinMode(led[i], OUTPUT); + } + + // Initialize all 4 Switches as inputs. + for (int i = 8; i<=11; i++) { + pinMode(i, INPUT); + } + + + // initialize timer1 --------------------------------------- + noInterrupts(); // disable all interrupts + TCCR1A = 0; + TCCR1B = 0; + TCNT1 = 0; + + OCR1A = 9000; // Load value to compare + TCCR1B |= (1 << WGM12); // CTC mode + TCCR1B |= (1 << CS10); // 64 prescaler + TCCR1B |= (1 << CS11); // + TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt + interrupts(); // enable all interrupts + // ---------------------------------------------------------- +} + +// Timer compare interrupt service routine ---------------------------- +ISR(TIMER1_COMPA_vect) { // Here we check variable "mode" to find out + // what funtion to run + if (mode == 'R') { // R for rotate, V for volume, the rest for + RotateLEDS(); // temperature reading + } + else if (mode == 'V') { + VolumeLEDS(); + } + else { + temperature_read (); + } +} +// -------------------------------------------------------------------- + + +void loop() { + + + // If button 1 is pressed change the variable "mode" to 'T' + // this will start reading temperature + if (!digitalRead(BUTTON_1)) { + mode = 'T'; + } + + // If button 2 is pressed play melody + if (!digitalRead(BUTTON_2)) { + melody(); + while (!digitalRead(BUTTON_2)); // Check if button is still pressed + // do nothing + } + + // If button 3 ispressed change the register "mode" to 'R' + // this will start the leds rotating sequence + if (!digitalRead(BUTTON_3)) { + mode = 'R'; + } + + // If button 4 ispressed change the register "mode" to 'V' + // this will start the leds volume simulator + if (!digitalRead(BUTTON_4)) { + mode = 'V'; + } +} + + +void RotateLEDS (void) { + + sensorValue = analogRead(rot); // read the analog value + // from POT + + if (sensorValue < 128) { + PORTD = 0x80; // Value to be displayed on leds + } + else if (sensorValue > 128 && sensorValue < 256) { + PORTD = 0x40; + } + else if (sensorValue > 256 && sensorValue < 384) { + PORTD = 0x20; + } + else if (sensorValue > 384 && sensorValue < 512) { + PORTD = 0x10; + } + else if (sensorValue > 512 && sensorValue < 640) { + PORTD = 0x08; + } + else if (sensorValue > 640 && sensorValue < 768) { + PORTD = 0x04; + } + else if (sensorValue > 768 && sensorValue < 896) { + PORTD = 0x02; + } + else { + PORTD = 0x01; + } + + // wait 60 milliseconds before the next loop + // for the analog-to-digital converter to settle + // after the last reading: + delay(60); + +} + +void VolumeLEDS (void) { + + sensorValue = analogRead(vol); // read the analog value + // from POT + + if (sensorValue < 128) { + PORTD = 0x80; // Value to be displayed on leds + } + else if (sensorValue > 128 && sensorValue < 256) { + PORTD = 0xC0; + } + else if (sensorValue > 256 && sensorValue < 384) { + PORTD = 0xE0; + } + else if (sensorValue > 384 && sensorValue < 512) { + PORTD = 0xF0; + } + else if (sensorValue > 512 && sensorValue < 640) { + PORTD = 0xF8; + } + else if (sensorValue > 640 && sensorValue < 768) { + PORTD = 0xFC; + } + else if (sensorValue > 768 && sensorValue < 896) { + PORTD = 0xFE; + } + else { + PORTD = 0xFF; + } + + // wait 60 milliseconds before the next loop + // for the analog-to-digital converter to settle + // after the last reading: + delay(60); +} + +void melody (void) // The following code and melody was taken +{ // from : http://arduino.cc/en/Tutorial/tone + // iterate over the notes of the melody: + for (int thisNote = 0; thisNote < BUZZ; thisNote++) { + + // to calculate the note duration, take one second + // divided by the note type. + //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. + int noteDuration = 500/noteDurations1[thisNote]; + tone(BUZZ, melody1[thisNote],noteDuration); + + // to distinguish the notes, set a minimum time between them. + // the note's duration + 30% seems to work well: + int pauseBetweenNotes = noteDuration * 1.80; // originally 1.30 + delay(pauseBetweenNotes); + + noTone(BUZZ); // stop the tone playing: + } + noTone(BUZZ); // stop the tone playing: +} + + +void temperature_read (void) +{ + // This routine was directly take from the OneWire examples + // library, please refer to : http://playground.arduino.cc/Learning/OneWire + // and : http://www.pjrc.com/teensy/td_libs_OneWire.html + + byte i; + byte present = 0; + byte type_s; + byte data[12]; + byte addr[8]; + + + if ( !ds.search(addr)) { + ds.reset_search(); + return; + } + + if (OneWire::crc8(addr, 7) != addr[7]) { + return; + } + + // the first ROM byte indicates which chip + switch (addr[0]) { + case 0x10: + type_s = 1; + break; + case 0x28: + type_s = 0; + break; + case 0x22: + type_s = 0; + break; + default: + return; + } + + ds.reset(); + ds.select(addr); + ds.write(0x44, 1); // start conversion, with parasite power on at the end + + // we might do a ds.depower() here, but the reset will take care of it. + present = ds.reset(); + ds.select(addr); + ds.write(0xBE); // Read Scratchpad + + for ( i = 0; i < 9; i++) { // we need 9 bytes + data[i] = ds.read(); + } + + // Convert the data to actual temperature + // because the result is a 16 bit signed integer, it should + // be stored to an "int16_t" type, which is always 16 bits + // even when compiled on a 32 bit processor. + int16_t raw = (data[1] << 8) | data[0]; + if (type_s) { + raw = raw << 3; // 9 bit resolution default + if (data[7] == 0x10) { + // "count remain" gives full 12 bit resolution + raw = (raw & 0xFFF0) + 12 - data[6]; + } + } + else { + byte cfg = (data[4] & 0x60); + // at lower res, the low bits are undefined, so let's zero them + if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms + else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms + else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms + // default is 12 bit resolution, 750 ms conversion time + } + raw = raw / 16; + PORTD = raw; +} + diff --git a/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_20/pitches.h b/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_20/pitches.h new file mode 100644 index 0000000..362aac8 --- /dev/null +++ b/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_20/pitches.h @@ -0,0 +1,94 @@ +/************************************************* + * Public Constants + *************************************************/ + +#define NOTE_B0 31 +#define NOTE_C1 33 +#define NOTE_CS1 35 +#define NOTE_D1 37 +#define NOTE_DS1 39 +#define NOTE_E1 41 +#define NOTE_F1 44 +#define NOTE_FS1 46 +#define NOTE_G1 49 +#define NOTE_GS1 52 +#define NOTE_A1 55 +#define NOTE_AS1 58 +#define NOTE_B1 62 +#define NOTE_C2 65 +#define NOTE_CS2 69 +#define NOTE_D2 73 +#define NOTE_DS2 78 +#define NOTE_E2 82 +#define NOTE_F2 87 +#define NOTE_FS2 93 +#define NOTE_G2 98 +#define NOTE_GS2 104 +#define NOTE_A2 110 +#define NOTE_AS2 117 +#define NOTE_B2 123 +#define NOTE_C3 131 +#define NOTE_CS3 139 +#define NOTE_D3 147 +#define NOTE_DS3 156 +#define NOTE_E3 165 +#define NOTE_F3 175 +#define NOTE_FS3 185 +#define NOTE_G3 196 +#define NOTE_GS3 208 +#define NOTE_A3 220 +#define NOTE_AS3 233 +#define NOTE_B3 247 +#define NOTE_C4 262 +#define NOTE_CS4 277 +#define NOTE_D4 294 +#define NOTE_DS4 311 +#define NOTE_E4 330 +#define NOTE_F4 349 +#define NOTE_FS4 370 +#define NOTE_G4 392 +#define NOTE_GS4 415 +#define NOTE_A4 440 +#define NOTE_AS4 466 +#define NOTE_B4 494 +#define NOTE_C5 523 +#define NOTE_CS5 554 +#define NOTE_D5 587 +#define NOTE_DS5 622 +#define NOTE_E5 659 +#define NOTE_F5 698 +#define NOTE_FS5 740 +#define NOTE_G5 784 +#define NOTE_GS5 831 +#define NOTE_A5 880 +#define NOTE_AS5 932 +#define NOTE_B5 988 +#define NOTE_C6 1047 +#define NOTE_CS6 1109 +#define NOTE_D6 1175 +#define NOTE_DS6 1245 +#define NOTE_E6 1319 +#define NOTE_F6 1397 +#define NOTE_FS6 1480 +#define NOTE_G6 1568 +#define NOTE_GS6 1661 +#define NOTE_A6 1760 +#define NOTE_AS6 1865 +#define NOTE_B6 1976 +#define NOTE_C7 2093 +#define NOTE_CS7 2217 +#define NOTE_D7 2349 +#define NOTE_DS7 2489 +#define NOTE_E7 2637 +#define NOTE_F7 2794 +#define NOTE_FS7 2960 +#define NOTE_G7 3136 +#define NOTE_GS7 3322 +#define NOTE_A7 3520 +#define NOTE_AS7 3729 +#define NOTE_B7 3951 +#define NOTE_C8 4186 +#define NOTE_CS8 4435 +#define NOTE_D8 4699 +#define NOTE_DS8 4978 + diff --git a/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_20_another/Makefile b/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_20_another/Makefile new file mode 100644 index 0000000..f34a17e --- /dev/null +++ b/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_20_another/Makefile @@ -0,0 +1,12 @@ +# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile + +BOARD_TAG = uno +BOARD_SUB = 8MHzatmega328 +USER_LIB_PATH += /home/ricardo/Arduino/libraries +ARDUINO_LIBS += OneWire + + ARDUINO_DIR = /home/ricardo/Installs/arduino-1.8.7 +MONITOR_PORT = /dev/ttyACM3 +-include /usr/share/arduino/Arduino.mk +-include /home/ricardo/Installs/Arduino-Makefile-1.6.0/Arduino.mk + diff --git a/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_20_another/ProtoIOsArduinoTester_20.ino b/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_20_another/ProtoIOsArduinoTester_20.ino new file mode 100644 index 0000000..cb670f7 --- /dev/null +++ b/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_20_another/ProtoIOsArduinoTester_20.ino @@ -0,0 +1,296 @@ +/* + PROTO I/Os arduino PCB TESTER. + This code tests all the devices in the PROTO I/Os arduino V1.0 PCB shield. + + Four buttons, buttons 3 and 4 have melodys. + Buttons 1 and 2 switch between a light + sequence on the board LEDs, or outputs the temperature read + by (DS18S20, DS18B20, DS1822) has a binary value on to the LEDs. + + + By Jony silva, www.electropepper.org , 02/12/2015 V1.0 + */ +#include "pitches.h" +#include + + +#define ON 1 +#define OFF 0 +#define BUTTON_1 8 +#define BUTTON_2 9 +#define BUTTON_3 10 +#define BUTTON_4 11 +#define BUZZ 13 // Buzzer is connected to digital output 13. +OneWire ds(12); // The DS18S20 is on digital output 12 + + +// Global variables ----------------------------------------------------------------------- +const int rot = A4; // Analog input pin to rotate leds +const int vol = A5; // Analog input pin to simulate volume +const char led[8] = {0,1,2,3,4,5,6,7}; // Start array with all 8 leds corresponding digital + // number +int sensorValue = 0; // value read from the pot +char mode = 'V'; // The mode for: 'V' voltage, 'R' rotate, 'T' temperature +//------------------------------------------------------------------------------------------ + + +// Function declarations ----------------------------------------------------------------------- +void VolumeLEDS (void); // Reads POT on A5, shows volume simulation acording to the value +void RotateLEDS (void); // Reads POT on A4, rotates the leds acording to the value +void melody (void); // Calls for melody one +void temperature_read (void); // Reads temperature and displays it in binary to the LEDs +//---------------------------------------------------------------------------------------------- + + +//---------------- MELODY --------------------------------------------------------------- +// Notes in the melody: +int melody1[] = {NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4}; +// Note durations: 4 = quarter note, 8 = eighth note, etc.: +int noteDurations1[] = {4,8,8,4,4,4,4,4}; +//----------------------------------------------------------------------------------------- + + + +void setup() { + + // Initialize all 8 digital I/O pins as outputs. + for (int i = 0; i<8; i++) { + pinMode(led[i], OUTPUT); + } + + // Initialize all 4 Switches as inputs. + for (int i = 8; i<=11; i++) { + pinMode(i, INPUT); + } + + + // initialize timer1 --------------------------------------- + noInterrupts(); // disable all interrupts + TCCR1A = 0; + TCCR1B = 0; + TCNT1 = 0; + + OCR1A = 9000; // Load value to compare + TCCR1B |= (1 << WGM12); // CTC mode + TCCR1B |= (1 << CS10); // 64 prescaler + TCCR1B |= (1 << CS11); // + TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt + interrupts(); // enable all interrupts + // ---------------------------------------------------------- +} + +// Timer compare interrupt service routine ---------------------------- +ISR(TIMER1_COMPA_vect) { // Here we check variable "mode" to find out + // what funtion to run + if (mode == 'R') { // R for rotate, V for volume, the rest for + RotateLEDS(); // temperature reading + } + else if (mode == 'V') { + VolumeLEDS(); + } + else { + temperature_read (); + } +} +// -------------------------------------------------------------------- + + +void loop() { + + + // If button 1 is pressed change the variable "mode" to 'T' + // this will start reading temperature + if (!digitalRead(BUTTON_1)) { + mode = 'T'; + } + + // If button 2 is pressed play melody + if (!digitalRead(BUTTON_2)) { + melody(); + while (!digitalRead(BUTTON_2)); // Check if button is still pressed + // do nothing + } + + // If button 3 ispressed change the register "mode" to 'R' + // this will start the leds rotating sequence + if (!digitalRead(BUTTON_3)) { + mode = 'R'; + } + + // If button 4 ispressed change the register "mode" to 'V' + // this will start the leds volume simulator + if (!digitalRead(BUTTON_4)) { + mode = 'V'; + } +} + + +void RotateLEDS (void) { + + sensorValue = analogRead(rot); // read the analog value + // from POT + + if (sensorValue < 128) { + PORTD = 0x01; // Value to be displayed on leds + } + else if (sensorValue > 128 && sensorValue < 256) { + PORTD = 0x02; + } + else if (sensorValue > 256 && sensorValue < 384) { + PORTD = 0x04; + } + else if (sensorValue > 384 && sensorValue < 512) { + PORTD = 0x08; + } + else if (sensorValue > 512 && sensorValue < 640) { + PORTD = 0x10; + } + else if (sensorValue > 640 && sensorValue < 768) { + PORTD = 0x20; + } + else if (sensorValue > 768 && sensorValue < 896) { + PORTD = 0x40; + } + else { + PORTD = 0x80; + } + + // wait 60 milliseconds before the next loop + // for the analog-to-digital converter to settle + // after the last reading: + delay(60); + +} + +void VolumeLEDS (void) { + + sensorValue = analogRead(vol); // read the analog value + // from POT + + if (sensorValue < 128) { + PORTD = 0xFF; // Value to be displayed on leds + } + else if (sensorValue > 128 && sensorValue < 256) { + PORTD = 0xFE; + } + else if (sensorValue > 256 && sensorValue < 384) { + PORTD = 0xFC; + } + else if (sensorValue > 384 && sensorValue < 512) { + PORTD = 0xF8; + } + else if (sensorValue > 512 && sensorValue < 640) { + PORTD = 0xF0; + } + else if (sensorValue > 640 && sensorValue < 768) { + PORTD = 0xE0; + } + else if (sensorValue > 768 && sensorValue < 896) { + PORTD = 0xC0; + } + else { + PORTD = 0x80; + } + + // wait 60 milliseconds before the next loop + // for the analog-to-digital converter to settle + // after the last reading: + delay(60); +} + +void melody (void) // The following code and melody was taken +{ // from : http://arduino.cc/en/Tutorial/tone + // iterate over the notes of the melody: + for (int thisNote = 0; thisNote < BUZZ; thisNote++) { + + // to calculate the note duration, take one second + // divided by the note type. + //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. + int noteDuration = 500/noteDurations1[thisNote]; + tone(BUZZ, melody1[thisNote],noteDuration); + + // to distinguish the notes, set a minimum time between them. + // the note's duration + 30% seems to work well: + int pauseBetweenNotes = noteDuration * 1.80; // originally 1.30 + delay(pauseBetweenNotes); + + noTone(BUZZ); // stop the tone playing: + } + noTone(BUZZ); // stop the tone playing: +} + + +void temperature_read (void) +{ + // This routine was directly take from the OneWire examples + // library, please refer to : http://playground.arduino.cc/Learning/OneWire + // and : http://www.pjrc.com/teensy/td_libs_OneWire.html + + byte i; + byte present = 0; + byte type_s; + byte data[12]; + byte addr[8]; + + + if ( !ds.search(addr)) { + ds.reset_search(); + return; + } + + if (OneWire::crc8(addr, 7) != addr[7]) { + return; + } + + // the first ROM byte indicates which chip + switch (addr[0]) { + case 0x10: + type_s = 1; + break; + case 0x28: + type_s = 0; + break; + case 0x22: + type_s = 0; + break; + default: + return; + } + + ds.reset(); + ds.select(addr); + ds.write(0x44, 1); // start conversion, with parasite power on at the end + + // we might do a ds.depower() here, but the reset will take care of it. + present = ds.reset(); + ds.select(addr); + ds.write(0xBE); // Read Scratchpad + + for ( i = 0; i < 9; i++) { // we need 9 bytes + data[i] = ds.read(); + } + + // Convert the data to actual temperature + // because the result is a 16 bit signed integer, it should + // be stored to an "int16_t" type, which is always 16 bits + // even when compiled on a 32 bit processor. + int16_t raw = (data[1] << 8) | data[0]; + if (type_s) { + raw = raw << 3; // 9 bit resolution default + if (data[7] == 0x10) { + // "count remain" gives full 12 bit resolution + raw = (raw & 0xFFF0) + 12 - data[6]; + } + } + else { + byte cfg = (data[4] & 0x60); + // at lower res, the low bits are undefined, so let's zero them + if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms + else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms + else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms + // default is 12 bit resolution, 750 ms conversion time + } + raw = raw / 16; + PORTD = raw; +} + diff --git a/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_20_another/pitches.h b/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_20_another/pitches.h new file mode 100644 index 0000000..362aac8 --- /dev/null +++ b/ProtoIOsArduino_Test_firmware/ProtoIOsArduinoTester_20_another/pitches.h @@ -0,0 +1,94 @@ +/************************************************* + * Public Constants + *************************************************/ + +#define NOTE_B0 31 +#define NOTE_C1 33 +#define NOTE_CS1 35 +#define NOTE_D1 37 +#define NOTE_DS1 39 +#define NOTE_E1 41 +#define NOTE_F1 44 +#define NOTE_FS1 46 +#define NOTE_G1 49 +#define NOTE_GS1 52 +#define NOTE_A1 55 +#define NOTE_AS1 58 +#define NOTE_B1 62 +#define NOTE_C2 65 +#define NOTE_CS2 69 +#define NOTE_D2 73 +#define NOTE_DS2 78 +#define NOTE_E2 82 +#define NOTE_F2 87 +#define NOTE_FS2 93 +#define NOTE_G2 98 +#define NOTE_GS2 104 +#define NOTE_A2 110 +#define NOTE_AS2 117 +#define NOTE_B2 123 +#define NOTE_C3 131 +#define NOTE_CS3 139 +#define NOTE_D3 147 +#define NOTE_DS3 156 +#define NOTE_E3 165 +#define NOTE_F3 175 +#define NOTE_FS3 185 +#define NOTE_G3 196 +#define NOTE_GS3 208 +#define NOTE_A3 220 +#define NOTE_AS3 233 +#define NOTE_B3 247 +#define NOTE_C4 262 +#define NOTE_CS4 277 +#define NOTE_D4 294 +#define NOTE_DS4 311 +#define NOTE_E4 330 +#define NOTE_F4 349 +#define NOTE_FS4 370 +#define NOTE_G4 392 +#define NOTE_GS4 415 +#define NOTE_A4 440 +#define NOTE_AS4 466 +#define NOTE_B4 494 +#define NOTE_C5 523 +#define NOTE_CS5 554 +#define NOTE_D5 587 +#define NOTE_DS5 622 +#define NOTE_E5 659 +#define NOTE_F5 698 +#define NOTE_FS5 740 +#define NOTE_G5 784 +#define NOTE_GS5 831 +#define NOTE_A5 880 +#define NOTE_AS5 932 +#define NOTE_B5 988 +#define NOTE_C6 1047 +#define NOTE_CS6 1109 +#define NOTE_D6 1175 +#define NOTE_DS6 1245 +#define NOTE_E6 1319 +#define NOTE_F6 1397 +#define NOTE_FS6 1480 +#define NOTE_G6 1568 +#define NOTE_GS6 1661 +#define NOTE_A6 1760 +#define NOTE_AS6 1865 +#define NOTE_B6 1976 +#define NOTE_C7 2093 +#define NOTE_CS7 2217 +#define NOTE_D7 2349 +#define NOTE_DS7 2489 +#define NOTE_E7 2637 +#define NOTE_F7 2794 +#define NOTE_FS7 2960 +#define NOTE_G7 3136 +#define NOTE_GS7 3322 +#define NOTE_A7 3520 +#define NOTE_AS7 3729 +#define NOTE_B7 3951 +#define NOTE_C8 4186 +#define NOTE_CS8 4435 +#define NOTE_D8 4699 +#define NOTE_DS8 4978 +