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

Nerves at home: Controlling a desk #23

Merged
merged 3 commits into from Jan 18, 2019

Conversation

Projects
None yet
3 participants
@jjcarstens
Copy link
Contributor

jjcarstens commented Jan 18, 2019

I've been doing a lot of projects around home using Nerves. Some have been for fun mainly for learning (like this one) and some are to serve a specific purpose.

This was a good learning experience, so thought I should share it. I'm planning on writing more about my other projects as I complete them and problem scope under Nerves At Home.

Let me know what you think

@ConnorRigby
Copy link
Collaborator

ConnorRigby left a comment

Wow this was great! just a couple little things i noticed here.

tags: ["nerves", "elixir", "uart", "logic analyzer", "elixir-circuits", "gpio"]
---

Use nerves and a little reverse engineering to contorl a motorized desk and

This comment has been minimized.

@ConnorRigby

ConnorRigby Jan 18, 2019

Collaborator
Suggested change Beta
Use nerves and a little reverse engineering to contorl a motorized desk and
Use Nerves and a little reverse engineering to control a motorized desk and

This comment has been minimized.

@jjcarstens

jjcarstens Jan 18, 2019

Author Contributor

Changed


It was a bit overwelming and confusing. There were hundreds of messages for just
simple movements and I was having trouble finding a pattern. I ended up pinging
the always helpful folks in the [nerves slack channel](https://elixir-lang.slack.com/messages/C0AB4A879/)

This comment has been minimized.

@ConnorRigby

ConnorRigby Jan 18, 2019

Collaborator
Suggested change Beta
the always helpful folks in the [nerves slack channel](https://elixir-lang.slack.com/messages/C0AB4A879/)
the always helpful folks in the [Nerves slack channel](https://elixir-lang.slack.com/messages/C0AB4A879/)

This comment has been minimized.

@ConnorRigby

ConnorRigby Jan 18, 2019

Collaborator

Also, can you also add a link to the forum here?

This comment has been minimized.

@jjcarstens

jjcarstens Jan 18, 2019

Author Contributor

Done

# setting LOW will move the desk in whatever direction the pin is for
# Be sure to initialize with HIGH to prevent moving on pin open.
{:ok, up_pin} = Circuits.GPIO.open(23, :output, initial_value: 1)
{:ok, down_pin} = Circuits.GPIO.open(24, :output, initial_value: 1)

This comment has been minimized.

@fhunleth

fhunleth Jan 18, 2019

Owner

Yay! You're using the new initial_value option.

This comment has been minimized.

@jjcarstens

jjcarstens Jan 18, 2019

Author Contributor

Ya, I was the one that wrote it into ElixirALE so was really glad you guys wrote it in new circuits.GPIO...really saved me!

update the view in real time on the backend when the socket reports height change.
You can see the reporting code at [here](https://github.com/jjcarstens/desk/blob/master/controller/lib/controller/reporter.ex).

It's not special, but you can check it out at: https://dudewheresmydesk.live

This comment has been minimized.

@fhunleth

fhunleth Jan 18, 2019

Owner

I'm dying.

This comment has been minimized.

@fhunleth
@jjcarstens

This comment has been minimized.

Copy link
Contributor Author

jjcarstens commented Jan 18, 2019

I also added one more picture and quick snippet showing a final setup in
7d107e4

Ready for another 👀

@fhunleth fhunleth merged commit 4fd9491 into fhunleth:master Jan 18, 2019

@fhunleth

This comment has been minimized.

Copy link
Owner

fhunleth commented Jan 18, 2019

I merged. Hopefully it renders ok for real and it's ready to be announced...

@fhunleth

This comment has been minimized.

Copy link
Owner

fhunleth commented Jan 18, 2019

Oh, and thanks! This is a super awesome post!

@fhunleth

This comment has been minimized.

Copy link
Owner

fhunleth commented Jan 18, 2019

It's live. I reread and realized that in my excitement, I skipped over the binary pattern match.

In the handle_info({:circuits_uart, name <<1, 1, base, height>>... function, you can simplify it a bit. Here's some iex prompt code:

iex(3)> <<_, _, height::size(16)>> = <<1, 1, 1, 53>>             
<<1, 1, 1, 53>>
iex(4)> height
309
iex(5)> height / 10
30.9

So in the pattern match part of the function, you can match on <<1, 1, height::size(16)>>. That extracts a 16-bit integer in big endian form. Then, because Elixir auto-converts to floats when running /, you can convert from 1/10th inch units to inches with a simple divide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment