Before you keep reading...
Runestone Academy can only continue if we get support from individuals like you. As a student you are well aware of the high cost of textbooks. Our mission is to provide great books to you for free, but we ask that you consider a $10 donation, more if you can or less if $10 is a burden.
Before you keep reading...
Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.
8.2. Reference manual¶
This provides a list of the items available in the
- 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:
This takes no parameters. It invokes the resetHardware function.
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.
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.
frequency: The frequency to do the PWM, in Hz.
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.
The function returns the actual PWM frequency, due to the limitations of the available clock divisor.
- Cellbot.ledcAttach(pin, channel)¶
Remove control of the pin from the associated PWM channel.
pin: The pin to detch from PWM control.
- Cellbot.ledcWrite(channel, duty_cycle)¶
Specify the duty cycle of the PWM.
channel: The PWM channel to use; a number between 0 and 15.
duty_cycle: The duty cycle, ranging from 2^resolution_in_bits (100%) to 1 (almost 0%). The
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:
Begin collecting data from the sensor.
Finish collecting data from the device. This saves battery life.
The following sensors have
- class cellbotics.Accelerometer¶
- class cellbotics.Gyroscope¶
- class cellbotics.Magnetomoter¶
Also known as a digital compass.
- class cellbotics.LinearAcceleration¶
- class cellbotics.GravitySensor¶
These two sensors produce a
quaternion property. See Quaternions and spatial rotation.
- class cellbotics.AbsoluteOrientationSensor¶
- class cellbotics.RelativeOrientationSensor¶
- 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: