Python Hardware (PenguinPi) Library Documentation
The documentation for the EGB320 penguinPi.py file can be found here. This file provides high level classes and functions for interacting with the hardware using Python.
Python Module Classes
Each class corresponds to a specific component of the hardware. Some less important functions have not been documented here.
THe classes are typically initialised using a string representing an address. The available addresses can be found in the following section.
UART
The UART module encapsulates the serial communication between the Raspberry Pi and the microcontroller on the hat. This class is used to automatically open a serial connection with the microcontroller when penguinPi is imported.
Motor
The Motor class is used for interacting with a pair of DC motors. These will typically be the main drive motors on the robot.
The functionality of this class can be tested by running test_motors.py and test_encoders.py.
set_velocity: Set the desired velocity of a motor. This should be an integer between -100 and 100.
set_target_velocity: Designed to be equivalent to SetTargetVelocities from the RoverBot module. This function should be called once for each motor. Inputs are two integers between -100 and 100, representing desired linear and rotational velocity. Note that this function is very basic and it is recommended to implement this logic yourself using the set_velocity function instead.
get_encoder: If a wheel encoder has been set up for this motor, then this function can be used to get the number of ticks from that encoder since the last reset.
LED
The LED class is used for controlling all the LEDs built into the hat. This does not include the main LED array.
The functionality of this class can be tested by running test_leds.py.
set_state: Set the state of one LED. A state of 1 corresponds to on, and 0 to off.
AnalogIn
This class is primarly used to monitor the battery voltage and current.
The functionality of this class can be tested by running test_adc.py.
get_value: Get a reading from one of the microcontroller's analog to digital converters. If the application is not very time sensitive then consider using get_smooth instead.
get_smooth: This has the same functionality as get_value, except that the microcontroller takes several readings and returns the average.
Hat
The Hat class bundles several smaller components together into one class. These include the DIP switches, the LED array and the OLED display.
The functionality of this class can be tested by running test_dip.py, test_ipaddr_set.py, test_leds.py and test_usertext.py.
get_dip: Read the builtin DIP switches. Returns a number with each binary digit representing the state of one switch. Switch 1 is the high-order bit.
refresh_ip_display: This function gets the Raspberry Pi's current IP addresses and Wi-Fi MAC address and displays them on the OLED display.
automatic_ip_display_update: This function launches a separate thread which will update the IP and MAC addresses displayed on the OLED. By default this occurs once every two minutes, but the interval can be set to any whole number of seconds using the optional second argument.
set_ledarray: Sets the state of all LEDs in the builtin array. The input should be an integer. The 16 least significant bits of it are used to set the values of the LEDs in the array.
Address Mapping
AD_ADC_C: Battery current sensor
AD_ADC_V: Battery voltage sensor
AD_HAT: PenguinPi hat
AD_LED_2: Builtin LED
AD_LED_3: Builtin LED
AD_LED_4: Builtin LED
AD_LED_B: Blue component of builtin RGB LED
AD_LED_G: Green component of builtin RGB LED
AD_LED_R: Red component of builtin RGB LED
AD_MOTOR_L: Left drive motor
AD_MOTOR_R: Right drive motor