gcormier / megadesk

Open-source IKEA Bekant controller board
GNU General Public License v3.0
717 stars 53 forks source link

Megadesk recalibration throws error #134

Closed buran-energia closed 1 year ago

buran-energia commented 1 year ago

Megadesk hangs and then throws error when I try to recalibrate using it. Megadesk is controlled via Serial using ESP32 (24V).

Since I can only control it via Serial, I am sending the command "<L,14.", which should be equal to "14 UP pushes" that launches a recalibration procedure. When I do this, the desk goes down to the lowest position, but then Megadesk does not respond to any Serial commands. This isn't normal, right? Then upon switching power, it gives me ">E96,0" error no matter the command I send (e.g. "<C,0."). What does this error even mean? I can bring the desk back to life by using the original controller and moving the desk a bit up, then changing back to Megadesk, but I prefer for recalibration to work via Megadesk.

Also I couldn't find anywhere in the docs: when do you need to recalibrate the motors? I assume it is when you get an error such as "DE4732,117" and the desk doesn't move to the correct preset position.

Other than the above issues, everything works.

AnAnalogGuy commented 1 year ago

Also I couldn't find anywhere in the docs: when do you need to recalibrate the motors? I assume it is when you get an error such as "DE4732,117" and the desk doesn't move to the correct preset position.

Recalibration i.e. is needed when the two legs of the table are not moving in sync anymore, meaning, one leg reaches the lower or upper end earlier than the other.

AnAnalogGuy commented 1 year ago

Megadesk hangs and then throws error when I try to recalibrate using it. Megadesk is controlled via Serial using ESP32 (24V).

Are you using a ESP32 on 3.3 Volt? I'm asking, as I also from time to time have issues with megadesk and/or the ESP board crashing. Greg pointed out that the signaling voltage of Megadesk is 5V which I guess is the root cause for the crashes I experience (meaning the problem is not the megadesk). Greg suggested to use a Voltage Level Shifter to make sure both boards are operating on 5V.

gcormier commented 1 year ago

Can you remove your serial connection (TX,RX,GND) to megadesk and attempt the recalibration procedure to see if it works?

gcormier commented 1 year ago

>E96,0 > start of comms E error 96 this is the target height it's trying to go to ,0 memory position 0 (ignore)

96 is too low. It's probably via these lines https://github.com/gcormier/megadesk/blob/523fab165acd7ceec9f8d6c0d7a8b89f20e3d5c2/code/src/megadesk.cpp#L767-L773

We could change this to look at the direction of movement to error out accordingly. Eg if we are too-low for some reason, it could still allow UP movement.

buran-energia commented 1 year ago

Recalibration i.e. is needed when the two legs of the table are not moving in sync anymore, meaning, one leg reaches the lower or upper end earlier than the other.

So basically if it throws me a DE*, error, I need to recalibrate. Will this happen often?

Are you using a ESP32 on 3.3 Volt? I'm asking, as I also from time to time have issues with megadesk and/or the ESP board crashing. Greg pointed out that the signaling voltage of Megadesk is 5V which I guess is the root cause for the crashes I experience (meaning the problem is not the megadesk). Greg suggested to use a Voltage Level Shifter to make sure both boards are operating on 5V.

I am using https://www.ezsbc.com/product/wifi01-sw/ as recommended on the site and haven't had any issues for a month now except the recalibration procedure. Does this thing need it? It is taking power from the same 24v source.

Can you remove your serial connection (TX,RX,GND) to megadesk and attempt the recalibration procedure to see if it works?

It would be a pain to start recalibration, since I didn't open the original enclosure and don't have any buttons attached to megadesk. But I might connect some other button if it is really needed and there is such option.

How the recalibration should work, btw? Once megadesk lowers the desk, the recalibration is completed right away, and it should answer via serial?

96 is too low. It's probably via these lines

But that wouldn't explain why it becomes unresponsive upon recalibration, right, not even giving me E96 error until I restart it?

gcormier commented 1 year ago

But that wouldn't explain why it becomes unresponsive upon recalibration, right, not even giving me E96 error until I restart it?

Correct, that is an odd one. I don't personally use serial control. But with just hardware, after recalibration, it will respond immediately.

Are you equipped to flash your megadesk with firmware?

buran-energia commented 1 year ago

Are you equipped to flash your megadesk with firmware?

I have FT232R (3.3v for logic) and CP2102 5v. I guess I should use the latter. It's been a while since I done it, but with some instructions I can do it.

gcormier commented 1 year ago

You'll need an AVRISP to re-flash it, not a serial converter. A Pi will work as well in a pinch.

buran-energia commented 1 year ago

You'll need an AVRISP to re-flash it, not a serial converter. A Pi will work as well in a pinch.

Oh, right, I forgot I probably used RPi for that. I got RPi3.

gcormier commented 1 year ago

In that case, if you are comfortable with it, you could flash some custom firmware that has different limits for the absolute min/max heights. If you are comfortable with git and vscode I can provide some guidance, otherwise I can give you a custom firmware to flash.

As for the AVR flashing itself yvia the Pi, you will need to rely on existing materials on the internet. I won't be able to assist much. ( https://github.com/gcormier/avr5hat/blob/main/code/pi_program.sh maybe be useful to you )

buran-energia commented 1 year ago

otherwise I can give you a custom firmware to flash.

That would be best. I will need to use a 3.3v-5v logic level shifter or what?

gcormier commented 1 year ago

That would be best. I will need to use a 3.3v-5v logic level shifter or what?

No, you can run megadesk at 3.3V and flash it. So just use the 3.3V from the Pi, MOSI/MISO and GND.

gcormier commented 1 year ago

megadesk-firmware-2023-04-23.zip

Here's a firmware you can try. It should allow you to move UP even if you are bottom'd out, or move down if you are at the very top.

This won't address the serial timeouts, but perhaps at least fix the other issue of being unable to move the desk ?

buran-energia commented 1 year ago

Need some help with flashing before I brick something.

I connected it all like this: https://www.rototron.info/wp-content/uploads/PiSPI01.jpg

Added this to avrdude.conf:

programmer
  id    = "linuxgpio";
  desc  = "Use the Linux sysfs interface to bitbang GPIO lines";
  type  = "linuxgpio";
  reset = 12;
  sck   = 11;
  mosi  = 10;
  miso  = 9;
;

Did "sudo /usr/bin/avrdude -p t841 -c linuxgpio -v -t" and got "avrdude: AVR device initialized and ready to accept instructions". So it looks like the connections are fine.

Modified pi_program.sh:

#!/bin/bash

firmware=megadesk-limit_fix-t841-serial.hex

DEVICE=t841

sudo avrdude -p $DEVICE -c linuxgpio -B 1MHz -v -U flash:w:$firmware:i #2>/dev/null

Can I run it? Or what else do I need?

gcormier commented 1 year ago

You can remove the fuses since they will already be set properly. Fuses would be the biggest risk when flashing.

On Tue, Apr 25, 2023, 5:29 PM buran-energia @.***> wrote:

Need some help with flashing before I brick something.

I connected it all like this: https://www.rototron.info/wp-content/uploads/PiSPI01.jpg

Added this to avrdude.conf:

programmer id = "linuxgpio"; desc = "Use the Linux sysfs interface to bitbang GPIO lines"; type = "linuxgpio"; reset = 12; sck = 11; mosi = 10; miso = 9; ;

Did "sudo /usr/bin/avrdude -p t841 -c linuxgpio -v -t" and got "avrdude: AVR device initialized and ready to accept instructions". So it looks like the connections are fine.

Modified pi_program.sh:

!/bin/bash

firmware=megadesk-limit_fix-t841-serial.hex

DEVICE=t841

LOW_FUSE=0xE2 HIGH_FUSE=0xD6 EXT_FUSE=0xFE

sudo avrdude -p $DEVICE -B 250khz -D -v -U hfuse:w:$HIGH_FUSE:m -U lfuse:w:$LOW_FUSE:m -U efuse:w:$EXT_FUSE:m #2>/dev/null sudo avrdude -p $DEVICE -B 1MHz -v -U flash:w:$firmware:i #2>/dev/null

Can I run it? Or what else do I need?

— Reply to this email directly, view it on GitHub https://github.com/gcormier/megadesk/issues/134#issuecomment-1522443651, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACAAC5YYNJK4M2MZH4YJF63XDA64FANCNFSM6AAAAAAXBGRLN4 . You are receiving this because you commented.Message ID: @.***>

buran-energia commented 1 year ago

(ignore the last 2 posts that I deleted, I issued wrong cmds).

Recalibration seems to work now. I flashed it, did "L,14.", it lowered the desk and didn't even hang.

gcormier commented 1 year ago

So I just dug through some more of the code, and the edge case was already accounted for

https://github.com/gcormier/megadesk/blob/523fab165acd7ceec9f8d6c0d7a8b89f20e3d5c2/code/src/megadesk.cpp#L754-L765

So it is weird that with stock firmware, you were not able to "escape" out of the lower limit.

gcormier commented 1 year ago

I don't even think it's possible, but I would be curious if you re-flashed the stock serial firmware if you have any issues. I verify the firmware after flashing all the units, so it should technically be impossible to have a "bad flash".

buran-energia commented 1 year ago

So I just dug through some more of the code, and the edge case was already accounted for

The code you linked seems to be related to manual move up and down, right? I don't have any up/down buttons connected to it and only control it using serial, remember? So after calibration, it would hang and after restart it would give me E96 error even for commands such as "C0,0" (get position). That was the problem.

buran-energia commented 1 year ago

I did recalibration again, it lowered the desk to minimum, and this time it hanged (no serial responses). But I repluged power, and I don't get the E96 error anymore with this fix and was able to move the desk with serial. So the new flash seems to have somewhat fixed my initial problem.

edit: did recal again, didn't hang. The worst type of bugs.

buran-energia commented 1 year ago

So hmm a new issue. Any idea why with this fix it sometimes lowers the table a bit upon pluging power? E.g. I plug the desk power, and the table goes down from 500 to 160 position for no reason. Any idea why it would move on its own now?

gcormier commented 1 year ago

There might be some issues with the legs/motors. Already the recalibration should not be going as low as it is. You could try to use the MIN limit functionality to set the lower limit to be a bit higher the the absolute minimum to solve the issue.

buran-energia commented 1 year ago

And a new one. It seems to have stopped remembering the positions I saved after the power is lost. E.g., I save positions using "<S500,2." and "<S1000,3.". Then unplug it for a few minutes, plug it back and I get a sad tone when trying to move to them. This wasn't a problem before flashing.

buran-energia commented 1 year ago

So basically once you cut desk power for a bit and plug it in, it always lowers the desk to minimum position for no reason by itself. And it doesn't seem to remember anything from the eeprom (e.g. <"R,2." will read zero despite there being a saved position before replugging).

You could try to use the MIN limit functionality to set the lower limit

There's some bigger issues. But if you mean setting the lowest limit using "L,11", it didn't work due to the eeprom issue I guess. I set it to 560 (verified using R.11.). Then after replugging power it reads 299.

gcormier commented 1 year ago

I'm still wondering if there's some serial hiccups at the start. Can you unhook the serial control to see if that behaviour happens when powering on?

On Tue, Apr 25, 2023, 9:01 PM buran-energia @.***> wrote:

So basically once you cut desk power for a bit and plug it in, it always lowers the desk to minimum position for no reason by itself. And it doesn't seem to remember anything from the eeprom (e.g. <"R,2." will read zero despite there being a saved position before replugging).

You could try to use the MIN limit functionality to set the lower limit

There's some bigger issues. But if you mean setting the lowest limit using "L,11", it didn't work due to the eeprom issue I guess. I set it to 560 (verified using R.11.). Then after replugging power it reads 299.

— Reply to this email directly, view it on GitHub https://github.com/gcormier/megadesk/issues/134#issuecomment-1522612325, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACAAC53QEF6CPAPOZTLX44TXDBXWTANCNFSM6AAAAAAXBGRLN4 . You are receiving this because you commented.Message ID: @.***>

buran-energia commented 1 year ago

Can you unhook the serial control to see if that behaviour happens when powering on?

I unplugged all cables going to ESP32. Still lowered the desk by itself upon getting power.

gcormier commented 1 year ago

Can you reach out to me via Tindie? Maybe there's a hardware issue.

On Tue, Apr 25, 2023, 9:23 PM buran-energia @.***> wrote:

Can you unhook the serial control to see if that behaviour happens when powering on?

I unplugged all cables going to ESP32. Still lowered the desk by itself upon getting power.

— Reply to this email directly, view it on GitHub https://github.com/gcormier/megadesk/issues/134#issuecomment-1522629923, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACAAC5YREGRGCBWBZ6AQT23XDB2K3ANCNFSM6AAAAAAXBGRLN4 . You are receiving this because you commented.Message ID: @.***>

buran-energia commented 1 year ago

Flashed megadesk-v2022.09-t841-serial.hex. It doesn't move the table on startup, but still doesn't remember positions.

gcormier commented 1 year ago

Faulty hardware