Help needed: Trying to write ADS1115 lib using Wafer #3

Closed
opened 2020-08-20 18:35:51 +12:00 by psteininger · 7 comments
psteininger commented 2020-08-20 18:35:51 +12:00 (Migrated from gitlab.com)

Hi @jimsy. Thanks for getting a cool project started.
I am just getting into Nerves and I2C connected chips, after a very long time writing enterprise (Java) and web apps (Ruby, Elixir).

I recently started on a personal project to get a system in place to monitor moisture and water my plants. I got the watering ok with Circuits.GPIO and now comes the time to deal with the analog inputs. I bought a bunch of ADS1115 chips, and I found a decent lib here: https://github.com/mmmries/ads1115. Michael only implemented single-shot reading, but I'd like to twiddle with the continuous mode, as the single shot readings are kind of all over the place.

I then came across Wafer, and I thought - well, it would be kind of cool to use it to re-engineer the library. I also started thinking of other chips I might use, such as the MCP23008 (if I remember correctly - it's the GPIO expander/multiplexer)

As I am a beginner in hardware programming, I could use some help and guidance getting started with Wafer and ADS1115. I'd love to write about it and share the work further.

I am located in Berlin, Germany, but I think we can find some overlap to chat.

Thanks!

Piotr

Hi @jimsy. Thanks for getting a cool project started. I am just getting into Nerves and I2C connected chips, after a very long time writing enterprise (Java) and web apps (Ruby, Elixir). I recently started on a personal project to get a system in place to monitor moisture and water my plants. I got the watering ok with `Circuits.GPIO` and now comes the time to deal with the analog inputs. I bought a bunch of ADS1115 chips, and I found a decent lib here: https://github.com/mmmries/ads1115. Michael only implemented single-shot reading, but I'd like to twiddle with the continuous mode, as the single shot readings are kind of all over the place. I then came across Wafer, and I thought - well, it would be kind of cool to use it to re-engineer the library. I also started thinking of other chips I might use, such as the MCP23008 (if I remember correctly - it's the GPIO expander/multiplexer) As I am a beginner in hardware programming, I could use some help and guidance getting started with Wafer and ADS1115. I'd love to write about it and share the work further. I am located in Berlin, Germany, but I think we can find some overlap to chat. Thanks! Piotr
psteininger commented 2020-08-20 21:25:15 +12:00 (Migrated from gitlab.com)

changed title from Hep needed: Trying to write ADS1115 lib using Wafer to He{+l+}p needed: Trying to write ADS1115 lib using Wafer

changed title from **Hep needed: Trying to write ADS1115 lib using Wafer** to **He{+l+}p needed: Trying to write ADS1115 lib using Wafer**
jimsy commented 2020-08-21 08:35:25 +12:00 (Migrated from gitlab.com)

Hi @psteininger.

I'm always happy to help with adding hardware support using Wafer. The first place to start is with the datasheet for the device you're using - can you post a link to it here?

Basically we need to translate the register map from the datasheet into code, and then work on implementing the useful commands in terms of those registers.

Regarding the MCP23008 - I already wrote a driver for the MCP23017 which is pretty much exactly the same chip, except with more pins. I have some MCP23017's around here somewhere, but I haven't tested it recently. I have a vague memory of being unhappy with the way I built Wafer's GPIO dispatchers, so I'm keen for any feedback you might have.

Hi @psteininger. I'm always happy to help with adding hardware support using Wafer. The first place to start is with the datasheet for the device you're using - can you post a link to it here? Basically we need to translate the register map from the datasheet into code, and then work on implementing the useful commands in terms of those registers. Regarding the MCP23008 - I already wrote a driver for the [MCP23017](https://gitlab.com/jimsy/mcp23017) which is pretty much exactly the same chip, except with more pins. I have some MCP23017's around here somewhere, but I haven't tested it recently. I have a vague memory of being unhappy with the way I built Wafer's GPIO dispatchers, so I'm keen for any feedback you might have.
psteininger commented 2020-08-21 18:31:45 +12:00 (Migrated from gitlab.com)

Hi @jimsy ,

Thanks for offering help. The datasheet for ADS1115 is here: https://www.ti.com/lit/ds/symlink/ads1115.pdf. I have learned a ton from reading it. It's an interesting chip. Adafruit did a nice job putting together a neat little board for it with resistors, and capacitors baked in.

Re: extender - this is fantastic! I didn't see the package on hex. Now I remember - I actually wanted to use the MCP23017 instead of MCP23008.

I'll be able to jump into things after the weekend. I'm away right now in Poland working on electrical in our camping cabin. I have a green house here too, where all the Pi automation will be working.

Hi @jimsy , Thanks for offering help. The datasheet for ADS1115 is here: https://www.ti.com/lit/ds/symlink/ads1115.pdf. I have learned a ton from reading it. It's an interesting chip. Adafruit did a nice job putting together a neat little board for it with resistors, and capacitors baked in. Re: extender - this is fantastic! I didn't see the package on hex. Now I remember - I actually wanted to use the MCP23017 instead of MCP23008. I'll be able to jump into things after the weekend. I'm away right now in Poland working on electrical in our camping cabin. I have a green house here too, where all the Pi automation will be working.
jimsy commented 2020-08-23 11:56:52 +12:00 (Migrated from gitlab.com)

Hi @psteininger.

So looking at the datasheet, it seems there's only four registers (the address register is really implied). You could get away with something like this as a start:

defmodule ADS1115.Registers do
  use Wafer.Registers

  defregister(:conversion, 0x00, :ro, 2)
  defregister(:config, 0x01, :rw, 2)
  defregister(:low_threshold, 0x02, :rw, 2)
  defregister(:high_threshold, 0x03, :rw, 2)
end

Once you have this you should be able to read and write the various registers. From there you can use binary pattern matching, the Bitwise module and/or the helpers in Wafer.Twiddles to implement the various commands that you need to implement. I suggest having a look at the code in my pca8641 driver, for examples of how to work with the registers.

I spent a week in Poland in 2003, I loved it and will definitely go back one day. Have a great weekend!

Hi @psteininger. So looking at the datasheet, it seems there's only four registers (the address register is really implied). You could get away with something like this as a start: ```elixir defmodule ADS1115.Registers do use Wafer.Registers defregister(:conversion, 0x00, :ro, 2) defregister(:config, 0x01, :rw, 2) defregister(:low_threshold, 0x02, :rw, 2) defregister(:high_threshold, 0x03, :rw, 2) end ``` Once you have this you should be able to read and write the various registers. From there you can use binary pattern matching, the `Bitwise` module and/or the helpers in `Wafer.Twiddles` to implement the various commands that you need to implement. I suggest having a look at the code in my [pca8641](https://gitlab.com/jimsy/pca9641/) driver, for examples of how to work with the registers. I spent a week in Poland in 2003, I loved it and will definitely go back one day. Have a great weekend!
psteininger commented 2020-09-30 21:43:02 +13:00 (Migrated from gitlab.com)

Hi @jimsy I realize it's been a month since your post.
First, thank you for writing and tips. I sadly didn't have time or energy to sit down and really dive into this. On one hand it's been really busy with going to Poland and working on little projects there, plus our daughter just started school and my wife had a knee surgery and complications, but on the other hand I have a huge imposter syndrome and I am overwhelmed with learning so much about how to program hardware.

I have been spoiled rotten by high level languages and even higher level abstractions for web and enterprise development. It always felt like playing with legos and occasionally making some glue to make things stick. This... the hardware stuff is like making lego pieces on a molecular level. I have immense respect for people who are doing this stuff daily. I have to remind myself that it's just a matter of time before it will start making more sense to me. So I'll be starting out something, bit by bit. Once I get the ADS1115 somewhat working, I will try to get the ADS1118 (the SPI based little brother to ADS1115) working.

But first things first... :)

Thanks again for pointers and support :)

Hi @jimsy I realize it's been a month since your post. First, thank you for writing and tips. I sadly didn't have time or energy to sit down and really dive into this. On one hand it's been really busy with going to Poland and working on little projects there, plus our daughter just started school and my wife had a knee surgery and complications, but on the other hand I have a huge imposter syndrome and I am overwhelmed with learning so much about how to program hardware. I have been spoiled rotten by high level languages and even higher level abstractions for web and enterprise development. It always felt like playing with legos and occasionally making some glue to make things stick. This... the hardware stuff is like making lego pieces on a molecular level. I have immense respect for people who are doing this stuff daily. I have to remind myself that it's just a matter of time before it will start making more sense to me. So I'll be starting out something, bit by bit. Once I get the ADS1115 somewhat working, I will try to get the ADS1118 (the SPI based little brother to ADS1115) working. But first things first... :) Thanks again for pointers and support :)
jimsy commented 2020-10-01 10:41:27 +13:00 (Migrated from gitlab.com)

Hi @psteininger.

I only do this stuff for fun myself and totally understand what you mean. I think it's important that those of us used to building with higher levels of abstraction learn to play in a lot of domains - doing embedded stuff has really helped me improve the efficiency of my code (a key feature of my work at Narrative) - but also my experience with higher level abstractions makes me see how I can make life better for people working with embedded. Wafer is essentially a pile of abstractions for exactly this.

Good luck with the chips you're working with. I think you'll find that it's actually a lot easier than you think it is. I've been able to write drivers and work with peripherals without anything fancier than a cheap multimeter.

I believe in you

Hi @psteininger. I only do this stuff for fun myself and totally understand what you mean. I think it's important that those of us used to building with higher levels of abstraction learn to play in a lot of domains - doing embedded stuff has really helped me improve the efficiency of my code (a key feature of my work at [Narrative](https://narrative.so)) - but also my experience with higher level abstractions makes me see how I can make life better for people working with embedded. Wafer is essentially a pile of abstractions for exactly this. Good luck with the chips you're working with. I think you'll find that it's actually a lot easier than you think it is. I've been able to write drivers and work with peripherals without anything fancier than a cheap multimeter. ![I believe in you](https://media.giphy.com/media/Uq43Uhfqlo0MIQVgI6/giphy.gif)
psteininger commented 2020-10-01 22:13:18 +13:00 (Migrated from gitlab.com)

Thanks for your encouragement @jimsy. I'm really excited to get into this more. I am enjoying the learning and discovery process so far.

For example: A few days ago I discovered that I2C has a significant limitation when it comes to cable length. Yesterday I discovered that SJT Bits makes a differential I2C extender, which negates much of that concern (I saw a youtube video of a guy using about 50m of cat 5 cable between the boards. I managed to order some from Italy today (it sees like a popular piece of hardware).

Today I am gonna start work on the ADS1115. I will first be checking if spraying the sensors with liquid plastic helped the stability of the signal (it would be all over the place). I also received 5 of the MCP23017 chips (already on neat PCBs). So there is fun to be had ;)

Cheers!

Thanks for your encouragement @jimsy. I'm really excited to get into this more. I am enjoying the learning and discovery process so far. For example: A few days ago I discovered that I2C has a significant limitation when it comes to cable length. Yesterday I discovered that SJT Bits makes a differential I2C extender, which negates much of that concern (I saw a youtube video of a guy using about 50m of cat 5 cable between the boards. I managed to order some from Italy today (it sees like a popular piece of hardware). Today I am gonna start work on the ADS1115. I will first be checking if spraying the sensors with liquid plastic helped the stability of the signal (it would be all over the place). I also received 5 of the MCP23017 chips (already on neat PCBs). So there is fun to be had ;) Cheers!
james closed this issue 2023-11-24 20:24:07 +13:00
Sign in to join this conversation.
No labels
renovate
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: james/wafer#3
No description provided.