ivanwick / bekantfirmware

Programmable position memory for IKEA BEKANT adjustable sit/stand desk
https://ivanwick.github.io/bekantfirmware
149 stars 9 forks source link

Remote control of Bekant table #8

Closed marcelrv closed 1 year ago

marcelrv commented 1 year ago

Hi,

I would like to be able to get current position & control of the table for further processing. Think of e.g.

There seem to be several pins fee and going to the 2nd connector. As I was trying to understand the datasheet, no hardware UART serial port is available to support that easily.

I was wondering if you think the softserial library would be conflicting with the current implementation https://download.mikroe.com/documents/compilers/mikroc/pic/help/software_uart_library.htm

I would connect that to a ESP32 or similar to add the (wifi/bt) connectivity obviously I could always snoop the LIN bus, but that seem to be bit indirect way of doing it...

I have little experience with PIC16 programming, would be great to have your thought to what extend this is possible/complicated. Or if you think there are easy alternative ways to do this. (I like your concept of preserving the original PCB/MCU as much as possible)

ivanwick commented 1 year ago

Hello, and thanks for your interest. I have recently revisited the datasheet for the BEKANT microcontroller (PIC16LF1938) and remembered your ideas for extending the firmware functionality.

First, to mention alternatives: you are probably aware of other projects to control the desk using different hardware platforms. Some of these are already designed with more extensibility in mind, so it is worthwhile to check them out as well. If you are considering adding another microcontroller such as a more capable ESP32, it may even be better to just replace the original PIC and do the LIN bus control on the ESP32 itself rather than handling communication with it.

That said, I do agree that the PIC is underutilized in the BEKANT, so there is an opportunity to add more capabilities.

The PIC's hardware UART is being used as a LIN transceiver connected to the bus with the table legs. I don't necessarily think it is a bad idea for another microcontroller to join the bus, because a new device doesn't need to be restricted to snooping, it can actually participate as a real ID on the bus. The PIC can continue to act as the LIN master and send/receive messages to devices other than the table legs.

For a separate channel to the PIC, the software UART library might work but I haven't tried it. Instead, I would suggest using a different protocol with hardware support. The PIC has what they call the Master Synchronous Serial Port (MSSP) which can do SPI and I2C. These are common interconnect busses between chips, so any other microcontroller is also likely to have good support.

According to the datasheet, SPI/I2C pins are on RA5, RC3, RC4, RC5. They are indeed traceable to unused pads on the other connector, and are available for use by the firmware.