8.2. Reference manual¶
This provides a list of the items available in the cellbotics
module.
8.2.1. CellBot¶
- class cellbotics.CellBot¶
This class uses a BLE (Bluetooth Low Energy) connection with an ESP32 running Arduino libraries to execute functions. An example of its use:
import cellbotics # Define the pin numbers we need. LED1 = 7 LED2 = 5 PB1 = 0 # Configure pins. cb = cellbotics.CellBot() cb.pinMode(LED1, cb.OUTPUT) cb.pinMode(PB1, cb.INPUT) # Set up PWM at 1000 Hz with 16-bit resolution. cb.ledcSetup(channel, 1000, 16) cb.ledcAttachPin(LED1, channel) # Operate at ~7.6 % (5000/2^16). cb.ledcWrite(channel, 5000)
The Arudino documentation describes the following methods for digital pins:
Constants to use with these functions:
- Cellbot.__init__()¶
This takes no parameters. It invokes the resetHardware function.
- Cellbot.resetHardware()¶
Reset the ESP32, leaving it in a default state.
- Cellbot.ledcSetup(channel, frequency, resolution_in_bits)¶
Configure a PWM channel. See the code sample above.
- Param:
channel: The PWM channel to use; a number between 0 and 15. Channels 0-7 auto-update new PWM periods, while channels 8-15 don’t.
- Param:
frequency: The frequency to do the PWM, in Hz.
- Param:
resolution_in_bits: The number of bits used to do the PWM. The maximum possible value is floor(log2(processor clock frequency/PWM frequency)); this cannot exceed 20. The processor clock frequency is either 80 MHz or 1 MHz.
- Returns:
The function returns the actual PWM frequency, due to the limitations of the available clock divisor.
- Cellbot.ledcAttach(pin, channel)¶
Give control of the pin to the specified PWM channel. After the pin is attached, the pinMode no longer determines the output of the pin. Detach it to pass control back to the pinMode.
- Param:
pin: the pin number to attach this PWM channel to. This is the same as the first parameter of pinMode, digitalRead, or digitalWrite.
- Param:
channel: The PWM channel to use; a number between 0 and 15.
- Cellbot.ledcDetach(pin)¶
Remove control of the pin from the associated PWM channel.
- Param:
pin: The pin to detch from PWM control.
- Cellbot.ledcWrite(channel, duty_cycle)¶
Specify the duty cycle of the PWM.
- Param:
channel: The PWM channel to use; a number between 0 and 15.
- Param:
duty_cycle: The duty cycle, ranging from 2^resolution_in_bits (100%) to 1 (almost 0%). The
resolution_in_bits
comes fromledcSetup
.
8.2.2. Sensors¶
The following classes provide a number of sensors. Example use:
import cellbotics
from time import sleep
a = cellbotics.Accelerometer()
a.start()
for i in range(10):
print(a.x, a.y, a.z)
sleep(1)
a.stop()
For more details on each sensor, see the Sensor API. These sensors all share the following methods:
- Cellbot.<SensorClass>.start()
Begin collecting data from the sensor.
- CellBot.<SensorClass>.stop()
Finish collecting data from the device. This saves battery life.
8.2.2.1. XYZ sensors¶
The following sensors have x
, y
, and z
properties.
- class cellbotics.Accelerometer¶
- class cellbotics.Gyroscope¶
- class cellbotics.Magnetomoter¶
Also known as a digital compass.
- class cellbotics.LinearAcceleration¶
- class cellbotics.GravitySensor¶
8.2.2.2. Orientation sensors¶
These two sensors produce a quaternion
property. See Quaternions and spatial rotation.
- class cellbotics.AbsoluteOrientationSensor¶
- class cellbotics.RelativeOrientationSensor¶
8.2.2.3. Other sensors¶
- class cellbotics.AmbientLightSensor¶
This clss provides one attribute,
illuminance
, which gives the current light level in lux.
- class cellbotics.GeolocationSensor¶
Results from the device’s GPS. Attributes:
latitude
longitude
altitude
accuracy
altitudeAccuracy
heading
speed