Balderbraa
Member
Greetings!
First i want to apologize for my English and I hope you understand me well enough to help me with some coding advice.
I have been around the forum for a couple of years and done some smaller project with PicAxe but nothing really big.
Half a year ago i started building two home servers for my dad and me based on the raspberry pi model B.
The plan was to make them syncronize with each other so if either of our houses burned down we still got the family album intact.
After a couple of months with research an a lot of trial and error I got the syncronisation working. Using "bit-torrent sync", the two servers will find each other when they are connected to the internet and syncronize to each other.
Since the place where my father lives is ridden with poweroutages
i thought it would be a good idea to build a UPS for the servers and it is here PicAxe are about to enter the scene.
After some thinking (and a lot of coffee) i stipulated some functional behaviour that i wanted to achive and some possible solution on how to
achieve it.
-1. If power goes down the UPS should send a shutdown signal to the Raspberry PI and wait until shutdown is complete.
Using diode mixing with the powersupply and battery the battery takes over instantly when power fails. Using a optocoupler to detect that
the main power is gone. The battery is connected via a pulse on/pulse off-relay controlled by a picaxe 14M2 so it can be completly disconnected by a
pulseout 5000,relay_off_pin.
On the RPI side I found some code to use interrupts with RPI to invoke a shutdown command.
-2. When shutdown is complete the UPS must disconnect the battery supply to conserve power.
When a RPI is shut down it still draw a lot of power and needs to disconnect the supply to save power.Since the RPI is shut down
it can´t communicate any more, but the TX-pin on the RPI goes from high to low whent the RPI is done shutting down.
This can be detected by the PicAxe who then can disconnect the battery. This is done by the relay. The RPI TX-pin have some "chatter" at
the start of boot who cant be disabled. This needs a solution.
-3. When power returns, the RPI shall start booting and the battery supply shall be reconnected and ready for new power outages.
Since the PicAxe also is powered from the main supply it will start from the beginning of its program when power comes back. This makes us
able to reconnect the battery to the supply line and then power up the RPI again.
-4. The UPS should detect if the RPI crashes or hangs during boot, shutdown or when it is running and then try a reboot by toggling power to the RPI.
I installed a script on the raspberry PI who toggles a pin 1 second high and then 9 second low to indicate running condition. Im thinking there is
a possibillity that the RPI may freeze up in both the high state and the low state but im not shure how i can detect both conditions without running
into trouble.
-5. If rebooting fails more than tree times the UPS should refuse to power up the RPI until i get a chance to watch the boot myself.
To detect this I could measure the time it takes before the toggling of the Pin that indicates running starts.
-6. The UPS should give clear visual or audio feedback on whats happening at all times.
This I guess can be done by keeping a flag-register of some sort, that is acted upon in the different operation modes. I have designed
The board so i can connect 3 LEDs to indicate: "Running on batteries"(Yellow), "Error" (RED) and A green led connected to the signal-line for
the "Running" signal
After this i designed a PCB in eagle and got it fabricated by OSH-park and the initial testing proved that every sub-function worked. (The eagle
schematic is attached as a .zip file but it is not wery tidy.
The following pinout was used:
C.5 Serial inn and a switch (Disconnect need to be issued)
C.4 Relay reset coil (Battery disconnected)
C.3 Low when main power is present. (No interrupt)
C.2 Relay set coil (Battery connected)
C.1 "RPI power control". Controls a 5V 3 A switchmode powersupply. Raspberry PI gets power when this is set high.
C.0 picaxe input<------------------------ RPI GPIO 24. Toggles pin on for 1 second then 9 seconds off
|
|------|>|-----GND
LED
B.0 Serout maybe connect Piezo to this at later point.
B.1 Connected to Yellow LED (Indicate running on batteries)
B.2 Connected to Red LED (Indicate error)
B.3 Picaxe output ----------------------> RPI GPIO 18. RPI running a script that detects when this goes high and initialize a shutdown.
B.4 Picaxe input <---------------------- RPI GPIO 14. When RPI is shut down this goes low.
B.5 A switch. High when pressed.
Then when i was about to start programming and make a fully working UPS, one of the great miracles of life happend. Got me a beatiful son and the
backupserver was placed on the shelf until further notice. Now i have some spare time again and want to see if its possible to finish the project.
I have found that i need help with a lot of things but first i need to brake it down in manageable pieces. So if you could help me with this i would be
forever grateful.
First i want to apologize for my English and I hope you understand me well enough to help me with some coding advice.
I have been around the forum for a couple of years and done some smaller project with PicAxe but nothing really big.
Half a year ago i started building two home servers for my dad and me based on the raspberry pi model B.
The plan was to make them syncronize with each other so if either of our houses burned down we still got the family album intact.
After a couple of months with research an a lot of trial and error I got the syncronisation working. Using "bit-torrent sync", the two servers will find each other when they are connected to the internet and syncronize to each other.
Since the place where my father lives is ridden with poweroutages
i thought it would be a good idea to build a UPS for the servers and it is here PicAxe are about to enter the scene.
After some thinking (and a lot of coffee) i stipulated some functional behaviour that i wanted to achive and some possible solution on how to
achieve it.
-1. If power goes down the UPS should send a shutdown signal to the Raspberry PI and wait until shutdown is complete.
Using diode mixing with the powersupply and battery the battery takes over instantly when power fails. Using a optocoupler to detect that
the main power is gone. The battery is connected via a pulse on/pulse off-relay controlled by a picaxe 14M2 so it can be completly disconnected by a
pulseout 5000,relay_off_pin.
On the RPI side I found some code to use interrupts with RPI to invoke a shutdown command.
-2. When shutdown is complete the UPS must disconnect the battery supply to conserve power.
When a RPI is shut down it still draw a lot of power and needs to disconnect the supply to save power.Since the RPI is shut down
it can´t communicate any more, but the TX-pin on the RPI goes from high to low whent the RPI is done shutting down.
This can be detected by the PicAxe who then can disconnect the battery. This is done by the relay. The RPI TX-pin have some "chatter" at
the start of boot who cant be disabled. This needs a solution.
-3. When power returns, the RPI shall start booting and the battery supply shall be reconnected and ready for new power outages.
Since the PicAxe also is powered from the main supply it will start from the beginning of its program when power comes back. This makes us
able to reconnect the battery to the supply line and then power up the RPI again.
-4. The UPS should detect if the RPI crashes or hangs during boot, shutdown or when it is running and then try a reboot by toggling power to the RPI.
I installed a script on the raspberry PI who toggles a pin 1 second high and then 9 second low to indicate running condition. Im thinking there is
a possibillity that the RPI may freeze up in both the high state and the low state but im not shure how i can detect both conditions without running
into trouble.
-5. If rebooting fails more than tree times the UPS should refuse to power up the RPI until i get a chance to watch the boot myself.
To detect this I could measure the time it takes before the toggling of the Pin that indicates running starts.
-6. The UPS should give clear visual or audio feedback on whats happening at all times.
This I guess can be done by keeping a flag-register of some sort, that is acted upon in the different operation modes. I have designed
The board so i can connect 3 LEDs to indicate: "Running on batteries"(Yellow), "Error" (RED) and A green led connected to the signal-line for
the "Running" signal
After this i designed a PCB in eagle and got it fabricated by OSH-park and the initial testing proved that every sub-function worked. (The eagle
schematic is attached as a .zip file but it is not wery tidy.
The following pinout was used:
C.5 Serial inn and a switch (Disconnect need to be issued)
C.4 Relay reset coil (Battery disconnected)
C.3 Low when main power is present. (No interrupt)
C.2 Relay set coil (Battery connected)
C.1 "RPI power control". Controls a 5V 3 A switchmode powersupply. Raspberry PI gets power when this is set high.
C.0 picaxe input<------------------------ RPI GPIO 24. Toggles pin on for 1 second then 9 seconds off
|
|------|>|-----GND
LED
B.0 Serout maybe connect Piezo to this at later point.
B.1 Connected to Yellow LED (Indicate running on batteries)
B.2 Connected to Red LED (Indicate error)
B.3 Picaxe output ----------------------> RPI GPIO 18. RPI running a script that detects when this goes high and initialize a shutdown.
B.4 Picaxe input <---------------------- RPI GPIO 14. When RPI is shut down this goes low.
B.5 A switch. High when pressed.
Then when i was about to start programming and make a fully working UPS, one of the great miracles of life happend. Got me a beatiful son and the
backupserver was placed on the shelf until further notice. Now i have some spare time again and want to see if its possible to finish the project.
I have found that i need help with a lot of things but first i need to brake it down in manageable pieces. So if you could help me with this i would be
forever grateful.
Attachments
-
77.4 KB Views: 5