diff options
author | Blaise Thompson <blaise@untzag.com> | 2021-01-24 22:27:03 -0600 |
---|---|---|
committer | Blaise Thompson <blaise@untzag.com> | 2021-01-24 22:27:03 -0600 |
commit | 54c117b6e8d65e9955a93de95a62e0f9ede7935c (patch) | |
tree | c05ceb5364db5171156b90115fd0621e270af1ab /digital-driver/firmware | |
parent | fff7837c10266b023c1c54e491cc9e11bf2e75f9 (diff) |
digital driver prototype
Diffstat (limited to 'digital-driver/firmware')
-rw-r--r-- | digital-driver/firmware/Master_Photoreactor_Controller/Master_Photoreactor_Controller.ino | 40 | ||||
-rw-r--r-- | digital-driver/firmware/Test Sketchs/Master_Random_LED_I2C/Master_Random_LED_I2C.ino | 134 | ||||
-rw-r--r-- | digital-driver/firmware/Test Sketchs/Slave_Random_LED_I2C/Slave_Random_LED_I2C.ino | 122 | ||||
-rw-r--r-- | digital-driver/firmware/firmware.ino (renamed from digital-driver/firmware/Slave_Photoreactor_Controller/Slave_Photoreactor_Controller.ino) | 0 |
4 files changed, 0 insertions, 296 deletions
diff --git a/digital-driver/firmware/Master_Photoreactor_Controller/Master_Photoreactor_Controller.ino b/digital-driver/firmware/Master_Photoreactor_Controller/Master_Photoreactor_Controller.ino deleted file mode 100644 index 8c2ffa4..0000000 --- a/digital-driver/firmware/Master_Photoreactor_Controller/Master_Photoreactor_Controller.ino +++ /dev/null @@ -1,40 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////////// -// Digital Photoreactor Controller Slave Program Controlled by I2C // -// Run this slave program on the Arduino Uno or Rasberry Pi. // -//////////////////////////////////////////////////////////////////////////////////// - -#include <Wire.h> - -#define I2C_SLAVE_ADDR 0x26 // I2C slave address (38, 0x26) - -void setup() -{ - // init the Wire object - Wire.begin(); - - // wait for slave to finish any init sequence - delay(2000); -} - -void loop() -{ - - //generate buffer containing data to send via I2C - uint8_t buf[1]; - buf[0] = 25; // adjusting this byte changes fan speed. Can be adjusted from 0 to 256. - buf[1] = 1; // adjusting this byte changes LED intensity. Can be adjusted from 0 to 256. - - // send buffer - Wire.beginTransmission(I2C_SLAVE_ADDR); - Wire.write( buf, 2); - Wire.endTransmission(); - - // delay 20 milliseconds to accomodate slave onReceive() - delay(20); - - /////////////////////// WHY DO I NEED THIS PART?////////////////////////// - Wire.requestFrom(I2C_SLAVE_ADDR, 1); - - // delay 1 second so user can watch results - delay(1000); -} diff --git a/digital-driver/firmware/Test Sketchs/Master_Random_LED_I2C/Master_Random_LED_I2C.ino b/digital-driver/firmware/Test Sketchs/Master_Random_LED_I2C/Master_Random_LED_I2C.ino deleted file mode 100644 index ac5f249..0000000 --- a/digital-driver/firmware/Test Sketchs/Master_Random_LED_I2C/Master_Random_LED_I2C.ino +++ /dev/null @@ -1,134 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////////// -// I2C test program for Digital Photoreactor Controller using TinyWireS library // -// Run this Master program on an Arduino Uno. // -//////////////////////////////////////////////////////////////////////////////////// -// This test program is adapted from the TinyWireS stress test program // -// developed by Scott Hartog: https://github.com/rambo/TinyWire // -// // -// The master program picks a random number of bytes between 1 and 12. // -// It then sends that many bytes of randomd data to the AtTiny85 slave. // -// Then, the master reads that same number of bytes back from the slave. // -// The recieved data is then compared to the original transmitted data. // -// The results of this comparison are displayed in the serial monitor. // -// The process is then looped. // -// // -// BREADBOARD SETUP: // -// Arduino Uno R3 (D18/SDA) = I2C SDA // -// connect to SDA on slave with external pull-up (~4.7K) // -// Arduino Uno R3 (D19/SCL) = I2C SCL // -// connect to SCL on slave with external pull-up (~4.7K) // -// Arduino Uno R3 (D2) // -// connect to !RST on slave // -// Can alternatively connect !RST on slave to the Ardiuno "!RESET" pin // -// // -//////////////////////////////////////////////////////////////////////////////////// - -#include <Wire.h> - -#define I2C_SLAVE_ADDR 0x26 // i2c slave address (38, 0x26) - -uint16_t count = 0; // total number of passes so far -uint16_t error_count = 0; // total errors encountered so far - -char c_buf[64]; // for creating messages - -void setup() -{ - - // init the serial port - Serial.begin(9600); - - // init the Wire object (for I2C) - Wire.begin(); - - // wait for slave to finish any init sequence - delay(2000); -} - -void loop() -{ - uint8_t i; - uint8_t req_rtn; // num bytes returned by requestFrom() call - uint8_t rand_byte_count; - uint8_t out_rand[16]; // data written from master - uint8_t in_rand[16]; // data read back from slave - - bool mismatch; - - // count total number of request - count++; - - // compute random number of bytes for this pass - rand_byte_count = random(16) + 1; - - // force the first three requests to be small so that the tx buffer doesn't overflow - // instantly and the user can see at least one successful transaction and some - // mismtaches before the usiTwiSlave.c library hangs on the line "while ( !txCount );". - if (count <= 3) rand_byte_count = 2; - - // generate, save, and send N random byte values - Wire.beginTransmission(I2C_SLAVE_ADDR); - for (i = 0; i < rand_byte_count; i++) - Wire.write(out_rand[i] = random(256)); - Wire.endTransmission(); - - // delay 20 milliseconds to accomodate slave onReceive() callback - // function. The actual time that slave takes is application dependent, but - // just storing the master's transmitted data does not take - // anywhere near 20ms. - delay(20); - - // read N bytes from slave - req_rtn = Wire.requestFrom(I2C_SLAVE_ADDR, (int)rand_byte_count); // Request N bytes from slave - for (i = 0; i < req_rtn; i++) - in_rand[i] = Wire.read(); - - // compare in/out data values - mismatch = false; - for (i = 0; i < rand_byte_count; i++) - mismatch = mismatch || (out_rand[i] != in_rand[i]); - - // increment the error counter if the number of byte variables don't match or - // if the data itself doesn't match - if (mismatch || (rand_byte_count != req_rtn)) - { - error_count++; - } - - // The rest of the program just displays the results to the serial port - - // display total requests so far and error count so far - snprintf(c_buf, sizeof(c_buf), "req: %3d,err: %3d", count, error_count); - Serial.println(c_buf); - - // display the random byte count, the number of bytes read back, and "MATCH"/"MISMATCH" - snprintf(c_buf, sizeof(c_buf), "size: %2d/%2d,%s", rand_byte_count, req_rtn, rand_byte_count != req_rtn?"MISMATCH <<--- !!!":"MATCH"); - Serial.println(c_buf); - - // display whether the data compare matched or mismatched - snprintf(c_buf, sizeof(c_buf), "data: %s", mismatch?"MISMATCH <<--- !!!":"MATCH"); - Serial.println(c_buf); - - // send up to three tx/rx bytes so that random data can be - // visually verified - if (rand_byte_count >= 1) - { - snprintf(c_buf, sizeof(c_buf), "rand[0]: %02x/%02x", out_rand[0], in_rand[0]); - Serial.println(c_buf); - } - - if (rand_byte_count >= 2) - { - snprintf(c_buf, sizeof(c_buf), "rand[1]: %02x/%02x", out_rand[1], in_rand[1]); - Serial.println(c_buf); - } - - if (rand_byte_count >= 3) - { - snprintf(c_buf, sizeof(c_buf), "rand[2]: %02x/%02x", out_rand[2], in_rand[2]); - Serial.println(c_buf); - } - - // delay 1 second so user can watch results - delay(1000); -} diff --git a/digital-driver/firmware/Test Sketchs/Slave_Random_LED_I2C/Slave_Random_LED_I2C.ino b/digital-driver/firmware/Test Sketchs/Slave_Random_LED_I2C/Slave_Random_LED_I2C.ino deleted file mode 100644 index ef9df86..0000000 --- a/digital-driver/firmware/Test Sketchs/Slave_Random_LED_I2C/Slave_Random_LED_I2C.ino +++ /dev/null @@ -1,122 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////////// -// I2C test program for Digital Photoreactor Controller using TinyWireS library // -// Run this slave program on the AtTiny85. // -//////////////////////////////////////////////////////////////////////////////////// -// This test program is adapted from the TinyWireS stress test program // -// developed by Scott Hartog: https://github.com/rambo/TinyWire // -// // -// The slave program receives via I2C N bytes of random data in a single // -// receiveEvent() callback and stores that data in a global buffer. // -// It then responds the first requestEvent() callback with the same data. // -// The requestEvent() callback overwrites the data buffer with zeros after // -// responding so it will only respond correctly to the first requestEvent() // -// callback after each receiveEvent() callback. Subsequent requestEvent() // -// will respond with 0xff for all data bytes. // -// // -// // -// SETUP: // -// AtTiny85 Pin 2 = PB3 = Blink LED // -// Attiny85 Pin 3 (PB4) = LED PWM // -// AtTiny85 Pin 5 (PB0/SDA) = I2C SDA // -// connect to SDA on master with external pull-up (~4.7K) // -// AtTinyPin 6 (PB1) = Fan PWM // -// AtTiny Pin 7 (PB0/SCL) = I2C SCL // -// connect to SCL on master with external pull-up (~4.7K) // -// AtTiny Pin 1 (PB5/!RST) // -// connect to reset on master (or just pull-up) // -// // -//////////////////////////////////////////////////////////////////////////////////// - -#include "TinyWireS.h" // wrapper class for I2C slave routines - -#define I2C_SLAVE_ADDR 0x26 // I2C slave address (38, 0x26), - -uint8_t master_data[16]; // global buffer to store data sent from the master. -uint8_t master_bytes; // global variable to number of bytes sent from the master. - -const int LEDPin = 4; //Arduino pin 4, pin 3 on AtTiny85 pinout -const int FanPin = 1; //Arduino pin 1, pin 6 on AtTiny85 pinout -const int BlinkPin = 3; //Arduino pin 3, pin 2 on AtTiny85 pinout - -// Gets called when the ATtiny85 receives an I2C write slave request -void receiveEvent(uint8_t num_bytes) -{ - uint8_t i; - - // save the number of bytes sent from the master - master_bytes = num_bytes; - - // store the data from the master into the data buffer - for (i = 0; i < master_bytes; i++) - master_data[i] = TinyWireS.receive(); - - // set LED and Fan PWM duty to random byte values recieved from the master - analogWrite(FanPin, master_data[0]); - analogWrite(LEDPin, master_data[1]); - - // blink LED whenever data is successfuly recieved - digitalWrite(BlinkPin, HIGH); - delay(10); - digitalWrite(BlinkPin, LOW); - delay(10); - -} - -// Gets called when the ATtiny receives an i2c read slave request -void requestEvent() -{ - uint8_t i; - - // send the data buffer back to the master - for (i = 0; i < master_bytes; i++) - TinyWireS.send(master_data[i]); - - // corrupt the byte values in the data buffer - // so that subsequent call won't match - for (i = 0; i < master_bytes; i++) - master_data[i] += 0x5a; - - // corrupt length of the request, but dont' make it zero - - // if the usiTwiSlave.c is working fine, then this number is completely irrelevant - // because the requestEvent() callback will not be called again until - // after the next receiveEvent() callback, so the master_data and - // master_bytes variables will be set by that call. - - // If the usiTwiSlave.c has the issue of calling the requestFrom() callback - // for each byte sent, the buffer will accumulate by this amount *for each byte - // in the original request*. - // - // Making it zero will obscure the 1-byte send issue in the usiTwiSlave.c - // that is being tested. - // Making it small will allow a few requests to succeed before the tx buffer - // overflows and the usiTwiSlave.c hangs on the "while ( tmphead == txTail );" - // line - master_bytes = 2; -} - -void setup() -{ - // initialize the TinyWireS and usiTwiSlave libraries - TinyWireS.begin(I2C_SLAVE_ADDR); // init I2C Slave mode - - // register the onReceive() callback function - TinyWireS.onReceive(receiveEvent); - - // register the onRequest() callback function - TinyWireS.onRequest(requestEvent); - - pinMode(LEDPin, OUTPUT); // set pin for LED PWM - pinMode(FanPin, OUTPUT); // set pin for Fan PWM - pinMode(BlinkPin, OUTPUT); // set pin to blink LED - - TCCR0B = TCCR0B & 0b11111000 | 0b001; // sets internal timer of AtTiny85 to 31250 Hz for fast PWM for controlling fan speed -} - -void loop() -{ - // this needs to be here - /////////////Does this really need to be here????? - //TinyWireS_stop_check(); - // otherwise empty loop -} diff --git a/digital-driver/firmware/Slave_Photoreactor_Controller/Slave_Photoreactor_Controller.ino b/digital-driver/firmware/firmware.ino index 8f7acbb..8f7acbb 100644 --- a/digital-driver/firmware/Slave_Photoreactor_Controller/Slave_Photoreactor_Controller.ino +++ b/digital-driver/firmware/firmware.ino |