Thursday, June 30, 2022

100 prisoners problem

 Watched a youtube video about the 100 prisoners problem. Of course needed to write a program to simulate and verify it.

Sunday, June 5, 2022

TensorFlow Lite person detection preview

 While testing out the TFLite micro example of person detection on SparkFun Edge, I needed a way to see what the camera is "seeing" for debugging purpose.

So, here is a simple script to preview the image and check the output of the model via serial connection .

Saturday, May 28, 2022

Jupyter container with xgboost, tensorflow, sklearn, and torch etc

Created a docker image for running Jupyter with common ML libraries.

Idea based on De-Mystifying XGBoost. But instead of deploying to cloud, this image focus on running the container locally.

Wednesday, May 25, 2022

Aqara Motion Sensor P1

 A few notes on using the Aqara Motion Sensor P1 with zigbee2mqtt and Home Assistant.

  • Sensitivity can be set within HA. Or, publishing the set message directly to Mosquitto. e.g. (change "the_device_friendly_name", "username", and "password" accordingly. The sensitivity can be "low", "medium", or "high"):

mosquitto_pub -t 'zigbee2mqtt/the_device_friendly_name/set' -m '{"motion_sensitivity": "high"}' -u username -P password

  • Remember to press the button at the back of the sensor once after changing the setting.
  • The sensor has the optional "no_occupancy_since" field that can be set to send out after it no longer detect occupancy. It can even be set to send out at different timeout values. This comes in handy when using it to turn off different devices. It can be set via the zigbee2mqtt UI.

  • To use the payload "no_occupancy_since" in automation condition, choose the "Template" condition type and check the desired value with "trigger.payload_json.no_occupancy_since":

Sunday, January 16, 2022

Compiling and deploying TinyML examples to SparkFun Edge

Trying out the SparkFun Edge board. Seems there are changes to the source repositories and many online instructions are outdated.

For example, to build and deploy the micro_speech example:

#set env
export BAUD_RATE=921600
export DEVICENAME=/dev/ttyUSB0

# compile the code
make micro_speech

# convert the binary. "~work/apollo3/downloads/AmbiqSuiteSDK-master" is where I have the SDK installed
arm-none-eabi-objcopy gen/bin/micro_speech gen/bin/micro_speech.bin -O binary

python ~/work/apollo3/downloads/AmbiqSuiteSDK-master/tools/apollo3_scripts/ --bin gen/bin/micro_speech.bin --load-address 0xC000 --magic-num 0xCB -o gen/bin/micro_speech_nonsecure_ota --version 0x0

python ~/work/apollo3/downloads/AmbiqSuiteSDK-master/tools/apollo3_scripts/ --load-address 0x20000 --bin gen/bin/micro_speech_nonsecure_ota.bin -i 6 -o gen/bin/micro_speech_nonsecure_wire --options 0x1

# deploy
python ~/work/apollo3/downloads/AmbiqSuiteSDK-master/tools/apollo3_scripts/ -b ${BAUD_RATE} ${DEVICENAME} -r 1 -f gen/bin/micro_speech_nonsecure_wire.bin -i 6