Programming with MicroPython: Onboard Sensors

Import FutureBoard Library

Import the Library to make use of its functions.

from future import *

02: Onboard Sensors

1. Buttons

sensor.btnValue(btn)

Parameter btn represents A or B button, accepted values are a, b.

2. Light Sensor

sensor.getLight()

Returns a value 0~4095.

3. Temperature Sensor

sensor.getTemp()

Returns a degree in Celsius, FutureBoard can measure temperatures from -40 to 80 degrees.

Sample Program for 1~3

from future import *

from time import sleep

screen.fill((0, 0, 0))
while True:
  if sensor.btnValue('a'):
    screen.text(str("Light: ")+str(sensor.getLight()),5,10,1,(0, 119, 255))
    sleep(0.5)
  if sensor.btnValue('b'):
    screen.text(str("Temp: ")+str(sensor.getTemp()),5,30,1,(0, 119, 255))
    sleep(0.5)

4. Accelerometer

Returns the accelerometer value of the 3 axis with G as the unit.

5. Tilt Angles

Returns the roll and pitch angle of the FutureBoard.

Sample Program for 4~5


6. Gesture Detection

8 kinds of gesture can be detected by the FutureBoard.

  1. ‘shake’

  2. ‘freefall’

  3. ‘tilt_up’

  4. ‘tilt_down’

  5. ‘tilt_left’

  6. ‘tilt_right’

  7. ‘face_up’

  8. ‘face_down’

7. Gesture Event Trigger

Sample Program for 6~7


8. Compass Calibration

Magnetometer and compass requires calibration before using.

9. Magnetic Strength

Returns the magnetic strength detected by the sensor with uT as the unit.

10. Compass Bearing

Returns the compass bearing.

Sample Program for 8~10

Last updated