From phyphox
Revision as of 09:03, 23 September 2022 by Sebastian Kuhlen (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The Puck.js is a small button style sensor box. It is open source and JavaScript code can be uploaded to the Puck.js allowing for almost arbitrary usage of its various sensors, LEDs and Bluetooth communication.

From version 1.1.12 phyphox will directly recognize available Puck.js in the Bluetooth scan dialog and offer reading their accelerometer, gyroscope, magnetometer, light sensor, thermometer or voltage from a specific GPIO pin. Until the release of version 1.1.12 or later if you are looking for a reference implementation to modify, you can get this set of experiment configurations here:


Custom code and experiment configuration

If you want to create your own experiment configuration with custom code, we recommend that you start with one of the examples from the Puck.zip above. Just download the zip file and open one of the contained phyphox files in a text editor. You will find, that the JavaScript code can be embedded in a rather clear form by creating several config blocks. However, there are a few things that you should keep in mind:

  • At the time of this writing, the puck.js supports a MTU of 53 byte, which means that any entry between config-tags and any data that you try to send back to phyphox in one go may not exceed 53 characters.
  • Phyphox strips leading and trailing whitespaces within the config tags. This allows you to indent your JavaScript without loosing characters in terms of the MTU, but this also means that a final line break to trigger execution either needs an additional character after that (for example a comment with just //) or you need to encode the line break as a carriage return character as we do in the examples (hexadecimal 0x0d).
  • In order to use the Bluetooth UART characteristics for communication, you should disable echo (echo(false) in the examples) and you should directly write to the characteristic to avoid splitting your string into multiple messages or some feedback from the interpreter. To do so, you can reuse the directOut function from the examples.

Let us know if you need any support or if you created something cool with this.