Linux Format

HID-den treasures

-

As mentioned earlier, on the top level of the Pyboard’s flash file system you’ll find boot.py. This script is the first thing to run when the Pyboard is powered up and is designed to change the way it behaves. Take a look at the content of the script and you’ll see several options commented out. We’re interested in the last one, which says it makes the Pyboard ‘act as a serial device and a mouse’.

If you were to uncomment the last line, save the file and reboot, then you wouldn’t be able to access the file system to write the code you need to actually control it. So let’s just uncomment and save boot.py and not reboot until we’ve put the following code in main.py and saved it: import pyb move = pyb.Accel() button = pyb.Switch() while True: if button(): pyb.hid((0, move.x(), -move.y(), 0)) pyb.delay(25) Here, as we’ve done before, we’ve created button and accelerome­ter objects and created an infinite loop with ‘while True’. Inside that loop we’ve asked that if the button should be pressed, we’ll move the mouse (using the hid method) towards the co-ordinates created by the accelerome­ter’s X and Y readings. The delay is for stability – feel free to adjust it to taste.

Once you’ve saved the script you can unmount the Pyboard and reboot it. Now, when you press the USR button on the Pyboard and tilt it around, the mouse cursor should start moving around on the screen. It’s fun, but it’s not really a 168MHz Cortex M4 CPU with hardware

floating point unit 1024KB flash ROM and 192KB RAM

Micro SD card slot

3-axis accelerome­ter (MMA7660) Real-time clock with optional

battery backup

30 GPIO pins 3x 12-bit analog to digital converters

(on 16 pins) 2x 12-bit digital to analog (DAC)

converters (on two pins)

4 LEDs (red, green, yellow and blue) On-board 3.3V LDO voltage regulator &

input voltage range 3.6V to 10V DFU bootloader in ROM for easy

upgrading of firmware

Newspapers in English

Newspapers from Australia