Raspberry Juice

From BitWizard WIKI
Jump to: navigation, search
The Raspberry Juice board


Overview

The Raspberry Juice serves as a power switch for the Raspberry Pi. This expansion board can turn the power on or off at a scheduled time. shop link

Specifications

The Juice always uses about 2mA/10mW. The board is rated for a maximum current of 1A.

Protocol definitions

The Raspberry Juice can be found using I2C or SPI at address 0xA4, and has the following read ports: All times are in ms, and are 32 bits in size.

Port Returned value (in milliseconds)
0x20 Time until power off
0x21 Time until power on
0x30 button active 0: don't react to button press. 1: react to button press (default), others: undefined.
0x31 external input active 0: inactive (default), 1: active, others: undefined.
0x32 external input polarity 0: active low (default), 1: active high, others: undefined.
0x33 power set on/off state 0: off, 1: on, others: undefined.
0x38 button active powerupstate 0: don't react to button press. 1: react to button press (default), others: undefined.
0x39 external input active powerupstate 0: inactive (default), 1: active, others: undefined.
0x3a external input polarity powerupstate 0: active low (default), 1: active high, others: undefined.
0x3b power set on/off state powerupstate 0: off, 1: on, others: undefined.

Additionally, the following can be written to the Juice:

Port Effect
0x20 Set the time in milliseconds until power off
0x21 Set the time in milliseconds until power on
0x30 button active 0: don't react to button press. 1: react to button press (default), others: undefined.
0x31 external input active 0: inactive (default), 1: active, others: undefined.
0x32 external input polarity 0: active low (default), 1: active high, others: undefined.
0x33 power set on/off state 0: off, 1: on, others: undefined.
0x38 button active powerupstate 0: don't react to button press. 1: react to button press (default), others: undefined.
0x39 external input active powerupstate 0: inactive (default), 1: active, others: undefined.
0x3a external input polarity powerupstate 0: active low (default), 1: active high, others: undefined.
0x3b power set on/off state powerupstate 0: off, 1: on, others: undefined.

Usage

Connect the raspberry pi to your raspberry juice by I2C or SPI. Take care that the "power" of the I2C or SPI connector on the 'juice is connected to the 5V of the 'pi. Connecting it to the 3.3V supply rails will most likely end in disaster.

Now connect the adapter that you normally use to power the 'pi to the USB connector on raspberry juice board. The raspberry pi should start to boot.

User input

If you hit the button on the 'juice the power to the 'pi will toggle. It is better not to do this when the 'pi is on, but you can force a shutdown this way, just like pulling the power cord.

When the 'pi is off, the 'juice will go into a power-saving mode. It will only test the button a few times per second. In this situation it is possible to press-and-release the button between two checks by the 'juice. To prevent this, you need a slightly longer press.

Software control

You can use SPI or I2C to tell the 'juice to do things with the power to the 'pi. First of all, writing a 32-bit integer to register 0x20 and 0x21 will schedule a power-down and a subsequent power-up after the specified number of miliseconds. This way you can put your 'pi to deep-sleep under software-control, and schedule a wakeup at some future time. An example might be that you have to perform a certain task every hour, but that task only takes a few minutes. So after performing the task, the 'pi will schedule a "poweron" event after about 60 minutes, perform a clean shutown, and then request a powerdown in the shutdown-procedure.

Halting the 'pi

In the function "do_stop () " in the file /etc/init.d/halt, just before the last line that has "halt" in it you can add:

 bw_tool -I -D /dev/i2c-1 -a a4 -W 20:800:i

this will powerdown the 'pi 2048 miliseconds after executing this command. This gives the 'pi time to finish the shutdown procedure, and then cuts the power.

Or you could write a 0 to register 0x33. That would immediately turn off the power.

Setting powerup-defaults

The module has to know what to do when IT first receives power. So you can write to registers 0x38 through 0x3b to set the default values that get loaded into the variables at 0x30-0x33 at powerup. The values you set are stored in eeprom and will be used on the next boot.

Sensitivity to inputs

The board can listen to the button on the board, as well as the external input. You could, for example, tell the board not to listen to the button while the 'pi is running. Then just before shutting down you enable the button again, and tell the 'juice to cut the power.

There is also an external input. You could connect an external switch, or drive it from some other source. Either the UP or the DOWN transition is considered an activation. You can set which one with the polarity variable.

Examples

So, for instance, writing 10000 to port 0x21 and 1000 to 0x20 will cut the power in 1 second, and then turn on the power 9 seconds later.

 bw_tool -I -D /dev/i2c-1 -a a4 -W 21:2710:i 20:3e8:i 

Note that bw_tool works with hexadecimal numbers. So 2710(hex) is 10000 decimal, and 3e8 is 1000 decimal.

Explanation of the command:

  • -I and -D /dev/i2c-1 specify that the module is the I2C version. If you use SPI0, you can leave these off. When you use SPI1, you would specify -D /dev/spidev0.1
  • -a a4 specifies the address of the module on the bus. 0xa4 is the 'juice address. You could change this, but this is usually not necessary (it does not make sense to have more than one of these modules).
  • -W specifies that you want to write to an address.
  • 21:2710:i is the register, 21, the value 0x2710 = 10000, and the datatype i=32-bit-integer.
  • 20:3e8:i is the register, 20, the value 0x3e8 = 1000, and the datatype i=32-bit-integer.