Pytronics
Pytronics is a Python library used to control the electronic hardware on the Rascal. It closely mirrors the library of functions used by the Arduino. This page describes the Pytronics functions available for use in response to web requests. If you need more detail, try looking at the Pytronics code itself.
Summary of useful URLs (coming in Cooties software release)##
The parts with angle brackets, like <analog pin>, mean "substitute a number in here."
The sections in braces, like { data: <data> } mean "pass JSON with your request that looks like this."
Name | Request | URL |
---|---|---|
analog read | GET | /analog/read/<analog pin> |
analog write | POST | (can't actually do this with current Rascal kernel) |
digital read | GET | /digital/read/<pin> |
digital write | POST | /digital/write/<pin>, { data: <data> } |
I2C read | GET | /i2c/read/<addr>/<reg>/<num_bytes> |
I2C write | POST | /i2c/write/<addr>/<reg>, { data: <data> } |
serial read | GET | /serial/read/<channel>/<speed>/<num_bytes> |
serial write | POST | /serial/write/<channel>/<speed>, { data: <data> } |
SPI read | GET | /spi/read/<channel>/<speed>/<num_bytes> |
SPI write | POST | /spi/write/<channel>/<speed>, { data: <data> } |
Other useful URLs (coming in Cooties software release)
Shortcuts
Name | Request | URL |
---|---|---|
digital toggle | GET or POST | /digital/toggle/<pin> |
digital write shortcut | GET or POST | /digital/write/<pin>/<state> |
BlinkM smart LED
Name | Request | URL |
---|---|---|
set hue, saturation and brightness | GET or POST | /blinkm/<address>/hsb/<hue>/<saturation>/<brightness> |
get hue, saturation and brightness | GET or POST | /blinkm/<address>/hsb |
4D Systems PICASO microLCDs
Name | Request | URL |
---|---|---|
clear LCD | GET or POST | /fd/clear-lcd |
draw filled rectangle | GET or POST | /fd/draw-filled-rectangle/<x1>/<y1>/<x2>/<y2>/<color> |
Rascal Micro precision voltage shield
Name | Request | URL |
---|---|---|
reset shield | GET or POST | /pvs/reset |
read voltages | GET or POST | /pvs/read |
Functions for reading data
digitalRead(pin)
The function digitalRead()
reads the voltage on one of the Rascal's digital pins. If the voltage is below 0.8 V, digitalRead()
returns 0. If the voltage is above 2.0 V, digitalRead()
returns 1. (Note that a voltage above 3.6 V will probably damage the Rascal's pins.)
Parameters
pin
String consisting of a pin name, like '2', '3', or 'LED'
Return type
Returns a string equal to either '0'
or '1'
.
analogRead(pin)
The function analogRead()
reads the voltage on one of the Rascal's analog inputs, scaled by the voltage on the A/D REF pin. A voltage of 0 V maps to a reading of 0. A voltage equal to or above the voltage on the A/D REF pin maps to a reading of 1023. (Note that a voltage above 3.6 V will probably damage the Rascal's pins.) Voltages in between 0 and A/D REF are mapped linearly between 0 and 1023. As an example, if you connect A/D REF to 3.3 V, a voltage of 1.65 V will produce a reading halfway between 0 and 1023 (roughly 512).
Parameters
pin
String consisting of an analog pin name, like 'A0', 'A1', 'A2', or 'A3'
Return type
Returns a string containing a number in the range 0-1023.
On error, returns "Not an analog pin. Try 'A0', 'A1', 'A2', or 'A3'."
i2cRead(addr, reg = 0, size = 'B')
The function i2cRead()
reads one or more bytes from a device on the I2C bus.
Parameters
addr
Chip addressreg
Memory address on chipsize
'C', 'W', 'B' or None, representing type of read requested, character, word, block, or short
Return type
Returns data read from device
spiRead()
The function spiRead()
is not implemented yet . . .
Parameters
chip
Return type
Returns data
Functions for sending data
digitalWrite(pin, state)
The function digitalWrite()
sets the voltage on one Rascal pin to either 3.3 V or 0 V, depending on the value of state passed in.
Parameters
pin
String consisting pin namestate
'HIGH' or 'LOW'
Return type
Returns None
i2cWrite(addr, reg, val = '', size = 'B')
The function i2cWrite()
sends one or more bytes onto the I2C bus.
Parameters
addr
Chip addressreg
Memory address on chipval
Data to writesize
'C', 'W', 'B' or None, representing type of write requested, character, word, block, or short
Return type
Returns None
serialWrite(text, speed=19200, port='1')
The function serialWrite()
is used to send data out the Rascal serial ports.
Parameters
text
String consisting of characters to be sent. Truncated after 80 characters.speed
(optional) Integer. Defaults to 19200.port
(optional) String ('1', '2', or '3'). Defaults to '1'.
Return type
Returns None
spiWrite(data, channel='0')
The function spiWrite()
sends data over one of the Rascal's four SPI channels. The maximum speed of the SPI port is limited in the kernel driver to 14.67 MHz, but can be decreased with an ioctl call that hasn't been sorted out yet.
Parameters
data
Integer or string to be sent.channel
(optional) String representing SPI channel to use ('0', '1', '2', or '3'). Defaults to '0'.
Return type
Returns None