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

Nerves at home: Controlling a desk #23

Merged
merged 3 commits into from
Jan 18, 2019
Merged

Nerves at home: Controlling a desk #23

merged 3 commits into from
Jan 18, 2019

Conversation

jjcarstens
Copy link
Collaborator

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

Copy link
Collaborator

@ConnorRigby ConnorRigby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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/)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay! You're using the new initial_value option.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm dying.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤣

@jjcarstens
Copy link
Collaborator 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
Copy link
Owner

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

@fhunleth
Copy link
Owner

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

@fhunleth
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants