Skip to content

Conversation

@JorgePe
Copy link

@JorgePe JorgePe commented Mar 24, 2025

Hi!
Someone asked me it it is possible to read the state of a reed switch with Pybricks so I searched for a way to create a custom LEGO compatible sensor, just a simple switch for a start, and found your library. Great work!!

I don't master Arduino, C++ or ESP32 but I managed to use it with a NodeMCU-ESP32 board I already had. Will try a Raspberry Pi Pico later since the ESP32 is overkill.

I am proposing the changes I made - it would help with issue #2

I only tested TiltSensor, it worked (just a typo in exemple). So I copied it and created a CustomSensor, it is basically just the TiltSensor Mode 0 with a different name ('MYOWNSWITH') and just one byte value. I am using Type ID 36 because it's not associated with any known LEGO device (tried higher values but didn't work with Pybricks - https://github.com/orgs/pybricks/discussions/2132).

I am proposing this new device with an example. You can see it working in this video: https://youtu.be/7tQd6HiykZE

In the video I am using a Technic Hub with Pybricks firmware and PUPDevice() class, then read(0)[0] to read mode 0.

Again, I am not a programmer so please excuse me if my code doesn't follow conventions or guidelines. Feel free to change it or even refuse it, I just want to contribute. I appreciate you mentioning me on your project and I also wanted to thank you because your worked helped me and I believe it will also help others.

JorgePe added 14 commits March 24, 2025 09:59
Add 'public' to TiltSensor class definition;
Add define condtions to work with ESP32 Seria1 UART
fixes example not compiling
fix example not compiling
propose 'CustomSensor' - it is a crippled version of 'TiltSensor' with a different ID (36d) , a different name for Mode 0 ('MYOWNSWITCH') and just one byte value
Folder for proposed new example
propose example for the CustomSensor, a switch connected to one GPIO pin
propose example for the CustomSensor, a switch connected to one GPIO pin
Add condition for ARDUINO_ARCH_RP2040 (like the Raspberry Pi Pico and the Seeed Studio XIAO RP2040)
Switch RX/TX pins for RP2040 boards. Thanks @arohrbacher
Add output  to Mode 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant