Installation Instructions - SimonTelescopium/PowerBuddy-Arduino-Sketch GitHub Wiki
- You need to have the Arduino IDE installed (download)
- From the '< > Code' tab download the latest .ino file, this is the latest Arduino sketch
- Open the Arduino IDE and use it to open the *.ino file
- Edit the sketch as indicated in the comments to configure the sketch to how you have set-up your Arduino.
- save the modified sketch then hit the upload button.
- Finally test the Arduino is responding as desired
- read the comments I spent ages writing them for you
You need to configure the Arduino sketch to suit your needs - don't worry it is easy and no coding experience is needed.
You will typically use an Arduino relay board or shield with your Arduino to create your PowerBuddy, so you will need connect digital pins from the Arduino to the relay board to control each relay, one pin per relay, we need to tell the Arduino what pins you have used for each relay, we do this in this line of code
int relayArray [8] = {4, 5, 6, 7, 8, 9, 2, 3};
each number in the curly braces is a digital pin and the order if sorted by the relay number, so in the example above I have...
- Relay 0 connected to digital pin 4
- Relay 1 connected to digital pin 5
- Relay 2 connected to digital pin 6
- Relay 3 connected to digital pin 7
- Relay 4 connected to digital pin 8
- Relay 5 connected to digital pin 9
- Relay 6 connected to digital pin 2
- Relay 7 connected to digital pin 3
If you have fewer relays still define them all by using unused digital pins - this is just a precaution as I didn't include any protective code to check you did this properly!
You need to tell the Arduino what switches can be controlled (i.e. they are relays) and which can't i.e. they are sensors, look for the following code...
EEPROM.write(addSWWrite,1); //switch 1 can control read/write
EEPROM.write(addSWWrite+1,1); //switch 2 can control read/write
EEPROM.write(addSWWrite+2,1); //switch 3 can control read/write
EEPROM.write(addSWWrite+3,1); //switch 4 can control read/write
EEPROM.write(addSWWrite+4,0); //switch 5 is read only/unused
EEPROM.write(addSWWrite+5,0); //switch 6 is read only/unused
EEPROM.write(addSWWrite+6,0); //switch 7 is read only/unused
EEPROM.write(addSWWrite+7,0); //switch 8 is read only/unused
The number after the comma indicates if you Arduino is a sensor (use 0) or a relay (use 1) simply change these to reflect your set-up
You can have up to 8 switches in any combination of relays and sensors, the Arduino needs to know how many you have (relays and sensors)
EEPROM.write(addnumSW,4);
search for the above code change the number to reflect your set-up, the above code says there are 4 switches
The Arduino will store the names of your switches, to do this you need to modify the code below, simply change the names to those you want but don't use colons ':' or hashes '#' in names and keep them to less than 30 characters (including spaces)
writeStringToEEPROM(addSWname,"EQ6 Power"); //name of switch 1 must be less than 30 characters
writeStringToEEPROM(addSWname+32,"Filterwheel Power"); //name of switch 2 must be less than 30 characters
writeStringToEEPROM(addSWname+64,"Dew Heater Power"); //name of switch 3 must be less than 30 characters
writeStringToEEPROM(addSWname+96,"Camera Cooler Power"); //name of switch 4 must be less than 30 characters
writeStringToEEPROM(138,"Switch 5 name must be <=30 chr"); //name of switch 5 must be less than 30 characters
writeStringToEEPROM(170,"Switch 6 name must be <=30 chr"); //name of switch 6 must be less than 30 characters
writeStringToEEPROM(202,"Switch 7 name must be <=30 chr"); //name of switch 7 must be less than 30 characters
writeStringToEEPROM(234,"Switch 8 name must be <=30 chr"); //name of switch 8 must be less than 30 characters
As with switch names they also have descriptions and these also need to be set in the code below, you can't use hashes'#' or colons ':' and decriptions must be under 62 characters.
writeStringToEEPROM(adddescription,"Toggle power on/off for EQ6 mount"); //description of switch 1 must be less than 62 characters
writeStringToEEPROM(adddescription+64,"Toggle power on/off for Filterwheel"); //description of switch 2 must be less than 62 characters
writeStringToEEPROM(adddescription+128,"Toggle power on/off for Dew heaters"); //description of switch 3 must be less than 62 characters
writeStringToEEPROM(adddescription+192,"Toggle power on/off for Camera cooler"); //description of switch 4 must be less than 62 characters
writeStringToEEPROM(adddescription+256,"description of switch 5 must be less than 62 characters"); //description of switch 5 must be less than 62 characters
writeStringToEEPROM(adddescription+320,"description of switch 6 must be less than 62 characters"); //description of switch 6 must be less than 62 characters
writeStringToEEPROM(adddescription+384,"description of switch 7 must be less than 62 characters"); //description of switch 7 must be less than 62 characters
writeStringToEEPROM(adddescription+448,"description of switch 8 must be less than 62 characters"); //description of switch 8 must be less than 62 characters
Each relay can have a power on state - this is the state you want the relay to be in when the Arduino powers up, if you haven't put a 10uF capacitor between GND and RESET then this will also be the state the Arduino resets to when the serial port connects! I STRONGLY recommend you include the capacitor across GND and RESET once you have finished uploading your sketch. edit the following code on the sketch to reflect what switches are on (1) and off (0) when the Arduino powers up.
EEPROM.write(addSWPowerOnStatus,0); //switch 1 off at arduino power-up
EEPROM.write(addSWPowerOnStatus+1,0); //switch 2 off at arduino power-up
EEPROM.write(addSWPowerOnStatus+2,1); //switch 3 on at arduino power-up
EEPROM.write(addSWPowerOnStatus+3,0); //switch 4 off at arduino power-up
EEPROM.write(addSWPowerOnStatus+4,0); //switch 5 off at arduino power-up
EEPROM.write(addSWPowerOnStatus+5,0); //switch 6 off at arduino power-up
EEPROM.write(addSWPowerOnStatus+6,0); //switch 7 off at arduino power-up
EEPROM.write(addSWPowerOnStatus+7,0); //switch 8 off at arduino power-up
The first time you upload your sketch (it's your sketch now) to the arduino you want it to store the defaults to do this we have to uncomment 1 line of code.
//EEPROM.write(0,0); // *** ------- uncomment to write default values ------- ***
remove the '//' so that it look like this
EEPROM.write(0,0); // *** ------- uncomment to write default values ------- ***
now upload your code - assuming all goes well you now need to comment out the line you just uncommented and upload it again so now change this line
EEPROM.write(0,0); // *** ------- uncomment to write default values ------- ***
and make it look like this...
//EEPROM.write(0,0); // *** ------- uncomment to write default values ------- ***
now upload your code this just makes sure the Arduino doesn't write defaults at each reboot.
Assuming this went well you can now proceed to testing...