Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I use the serial commands? #58

Closed
rhannink opened this issue May 19, 2021 · 16 comments
Closed

How do I use the serial commands? #58

rhannink opened this issue May 19, 2021 · 16 comments
Assignees
Labels
discussion todo Will be worked on

Comments

@rhannink
Copy link

Hello,

First off all, great product, works like a charm, but I would like to connect it to my domotic system (HA) and Google system.
I recompiled the code with the #define SERIALCOMMS.

I flashed the firmware with a pocket AVR programmer and this all works fine.

When I connect an FDTI232 to the pins MISO and SCK I see the following commands in my terminal when I press the up or down button.

14:51:02.422 -> <+���<+���<+���<+���<+���<+���<+���<+���<=�z�<+���<=�⸮�<+���<=�⸮�<+���<=�⸮�<+���<=�⸮�<+� �<=�⸮�<+� �<=�⸮�<-� �<-���<-���<-���<-���<-���<-���<-���<-���<-���<-���<-���<-���<=�⸮�<-���<=�⸮�<-���<=�⸮�<-���<=�{�<-���<=�f�<-� �<=�Z�<-� �<=�Q�<-���<=�N�<+���<+���<+���<+���<=�⸮�<+���<=�⸮�<+���<=�⸮�<+���<=�⸮�<+���<=�⸮�<+� �<=�⸮�<+� �<=�⸮�<-� �<-���<-���<-���<-���<=�⸮�<-���<=�⸮�<-���<=�o�<-���<=�W�<-���<=�B�<-� �<=�6�<-� �<=�-�<-���<=�*�<+���<+���<+���<+���<+���<+���<+���<+���<+���<+���<=�⸮�<+���<=���<+���<=�)�<+���<=�>�<+���<=�P�<+� �<=�\�<+� �<=�e�<-� �<-���<-���<-���<-���<-���<=�⸮�<-���<=�⸮�<-���<=�⸮�<-���<=�⸮�<-���<=�⸮�<-� �<=�⸮�<-� �<=�⸮�<-���<=�{�<+� �<+� �<+���<+���<=�⸮�<+���<=�⸮�<+���<=�⸮�<+���<=�

So that looks ok, but how can I sent a command via a serial terminal program? I tried to sent <- and <+ with or without returns, but nothing happens. What am I missing. Do i need to sent more bytes ? Can I use a serial terminal command line at all to sent commands?

Eventually I would like to use an ESP(8266 or 32) to control the megadesk. Maybe someone has some example code on what command/bytes exactly to sent over the serial line?

Thanks in advance
Remco

@rhannink rhannink changed the title How do I use the serail commando? How do I use the serial commands? May 19, 2021
@tagno25
Copy link
Contributor

tagno25 commented May 22, 2021

Here is where I described the command structure
#12 (comment)

The commands are mostly binary, with ASCII command indicators.

For initial testing I was using Termite with the "Hex View" plugin.

@rhannink
Copy link
Author

Thanks,

Ik will look into that...

@philwmcdonald
Copy link
Contributor

philwmcdonald commented Jun 8, 2021

With #70 there's the option of enabling pure ascii commands/responses. No need to read/write raw bytes over serial to control.
format is very similar to before:

<W3000,3.     # writes  location 3 with height 3000.
<T3000,255.   # plays a 3000Hz tone for 1sec
<C0.0.        # reports current height
<+300..       # nudge desk up by 300
<L,5.         # recall position from slot 2
<l,5.         # recall position from down-button slot 2
<R.0/         # read eeprom slot 0

After the marker byte '<', there's the Command byte, then two fields of ascii integer digits.
Terminate each field with any non-digit character eg !,./ or a line-break.
missing digits are interpreted as a 0 so <L.. is valid and passes two 0s to the L command.
First field (position) can be any number up to a maximum of 65535, the second field (slot) has a maximum of 255.

  data start (first byte)
    char   meaning
  -----------------
    <      start Rx Marker

  command (second byte)
    cmd    meaning
  -----------------
    +      increase
    -      decrease
    =      absolute
    C      Ask for current location
    S      Save location to (UpButton) EEPROM
    s      Save location to Downbutton EEPROM
    L      Load (Upbutton) location from EEPROM and move
    l      load Downbutton location from EEPROM and move
    W      Write arbitrary data to EEPROM
    R      Read arbitrary data from EEPROM
    T      play tone

  position (third/fourth bytes or 1st digit field. max 65535)
    cmd    meaning
  -----------------
    +-     relative to current position
    =SsW   absolute position
    T      tone frequency
    CRLl   (ignore)

  push_addr (fifth byte or 2nd digit field. max 255)
    cmd    meaning
  -----------------
    SLlWwR EEPROM pushCount/slot
    T      tone duration/4 ms. (250 == 1s)
    +-=C   (ignore)

@rhannink
Copy link
Author

rhannink commented Dec 6, 2021

Hello,

Finally found time to implement the serial commands. I flashed the latest firmware with the serial commands enabled and connected a esp8266 to the serial port. I loaded the following ESPHOME code onto the ESP and now I can control my Ikea desk from Home Assistant and through Google Home (Ok Google activate standing/sitting/middle)

  name: desk
  platform: ESP8266
  board: d1_mini

logger:

api:
  password: ""

ota:
  password: ""

wifi:
  ssid: "xxxxxxxxxxx"
  password: "xxxxxxxxx"

  ap:
    ssid: "Desk Fallback Hotspot"
    password: "xxxxxxxxxx"

captive_portal:

uart:
  baud_rate: 115200
  tx_pin: D0

switch:
  - platform: uart
    name: "Desk up"
    data: '<L0,4.'
  - platform: uart
    name: "Desk down"
    data: '<L0,3.'
  - platform: uart
    name: "Desk middle"
    data: '<L0,5.'

This code automatically gives me 3 switches within HA.
Works great, also the possibility to recalibrate and set the min and max heigth is a welcome addition.

Gr. Remco

@gcormier
Copy link
Owner

gcormier commented Dec 6, 2021

Wow, that's awesome that it was so easy with esphome! Nice work!

@rhannink
Copy link
Author

rhannink commented Dec 6, 2021

Only to bad, the power regulators of the megadesk can only deliver 5V/500mA. Now I need an additional powersupply to feed the ESP. Maybe in a new version you can upgrade the regulators to 1A or 1.5A types (they have same package I think). And maybe add an extra sideways connector with RX,TX,5V and GND. The current header cannot have a paring connector due to the height of the housing.

Keep up your great work...

Remco

@gcormier
Copy link
Owner

gcormier commented Dec 6, 2021

The issue is not the part itself, but the thermal limitations of a linear regulator in a small space.

https://www.gadgetronicx.com/calculators/linear-regulator-power-dissipation-calculator/

It is best to tap the 24V(30V) independently to power the secondary MCU with an independent regulator, DC BUCK or linear.

@rhannink
Copy link
Author

rhannink commented Dec 7, 2021

Maybe it helps if you cascade the 7812 and the 7805 to lower the voltagedrop, but the 7812 then needs to deliver more power, still a lot of heat dissipation.
I will use a buck converter to bring down the 24V to 5V.

Thanks.

@gcormier
Copy link
Owner

gcormier commented Dec 7, 2021

At the end of the day there is still around 7-13W of power to dissipate. A buck would be best for sure :)

@benfysh
Copy link

benfysh commented Mar 13, 2022

@rhannink have you documented this in more detail anywhere? Thanks

@rhannink
Copy link
Author

rhannink commented Mar 16, 2022

Hello @benfysh,

I did not find the time to document this project on GitHub. What I did was:

  • Buy Megadesk controller on Tindie. https://www.tindie.com/products/gcormier/megadesk/
  • Flash the controller with the latest firmware with serial commands enabled. You need the Sparkfun AVR programmer for this
  • Flash a Wemos D1 mini (or any other ESP) with the esphome software.
  • Connect de D0 pin from the ESP8266 (TX1) to the RX pin of the megadesk (PIN 4 MOSI)
  • Power the ESP8266 from the Ikea Desk by using a 24-5V Buck converter
  • Configure the ESP8266 in Home Assistant with the following settings:
 name: desk
  platform: ESP8266
  board: d1_mini

logger:

api:
  password: ""

ota:
  password: ""

wifi:
  ssid: "xxxxxxxxxxx"
  password: "xxxxxxxxx"

  ap:
    ssid: "Desk Fallback Hotspot"
    password: "xxxxxxxxxx"

captive_portal:

uart:
  baud_rate: 115200
  tx_pin: D0

switch:
  - platform: uart
    name: "Desk up"
    data: '<L0,4.'
  - platform: uart
    name: "Desk down"
    data: '<L0,3.'
  - platform: uart
    name: "Desk middle"
    data: '<L0,5.'

Now you have 3 switches available in HA for 3 different presets (I have 3 presets programmed in the megadesk controller 1-low, 2-high and 3-in between).

@tobru
Copy link

tobru commented Mar 16, 2022

I wrote a blog post about it, maybe it helps: https://tobru.ch/ikea-bekant-table-control-over-mqtt-with-megadesk-and-esp32/

@benfysh
Copy link

benfysh commented Mar 16, 2022

@rhannink & @tobru thanks both looks like I have a few more things to buy :) Megadesk is already working well for me I just like the idea of automating it and running automation when it is set to different heights.

@rhannink
Copy link
Author

@benfysh , indeed it is very cool, once it is hooked up to HA you can also control it with Google Home. "Ok Google I want to standup", "Ok Google, I want to sit down".

@gcormier gcormier self-assigned this Mar 17, 2022
@gcormier gcormier added the todo Will be worked on label Mar 17, 2022
@gcormier
Copy link
Owner

Gonna add a todo to bring out some info in the docs so people don't have to dig in issues for the commands.

@gcormier
Copy link
Owner

Added serial/esphome documentation to bottom of readme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion todo Will be worked on
Projects
None yet
Development

No branches or pull requests

6 participants