Go Down

Topic: ADS1115 with Arduino Python (Read 2166 times) previous topic - next topic

pax_electronica

Nov 25, 2019, 07:46 am Last Edit: Nov 25, 2019, 07:52 am by pax_electronica
Hi,

I was unable to use the ADS1115 AD converter with Python. Is it supported? A quick search showed up examples using RP but not on Arduino.

I am running Arduino from Anaconda with Python3. I tried to install packages related to ADS1x15 chips by doing:

    >  pip install adafruit-circuitpython-ads1x15
    >  pip install adafruit-blinka
    >  pip install adafruit_ads1x15

And run a simple example shown here:
         https://circuitpython.readthedocs.io/projects/ads1x15/en/latest/examples.html

However, I got unsatisfied packages in these two lines:

       import adafruit_ads1x15.ads1115 as ADS
       from adafruit_ads1x15.analog_in import AnalogIn

In the project interpreter window I see Adafruit-ADS1x15 and a few items seemingly related to ADS1x15. A screen shot is attached.

Does the chip have Python support on Arduino UNO?



 

Robin2

AFAIK CircuitPython is a version of MicroPython and is intended to be uploaded on high-end microprocessors such as the ESP32.

It certainly won't work on an Uno or Mega.


It will be much easier to help if you give a full description of the project you are trying to create.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

pax_electronica

My project for now is almost the same as this: https://realpython.com/arduino-python/. The only change is that in stead of the 10-bit analog pins on the Arduino, I want to use a 16-bit AD converter ADS1x15.

Eventually, I would like to plot analog sensor input versus time using Python's plotting packages. For that, I would always be running with a PC attached, leveraging its big screen,keyboard, and everything else. So I don't need to run micro-Python independently on the microcontroller, which seems to be a goal for CircuitPython.

With an UNO tethered to a PC, would it be possible to use ADS1X15 in Python code? If no ready-made package is available, what would it take to write one? Is there any references in that area?




Robin2

My project for now is almost the same as this: https://realpython.com/arduino-python/. The only change is that in stead of the 10-bit analog pins on the Arduino, I want to use a 16-bit AD converter ADS1x15.

[.....]

With an UNO tethered to a PC, would it be possible to use ADS1X15 in Python code?
This is a bit confused.

In the link you posted in Reply #2 it seems that the Python code is running on a PC (in which I include a RaspberryPi).

You should be able to write an Arduino program to collect data from the ADS1X15 as it seems to have an I2C interface.

Then you can have the Arduino send the data to a Python program running on your PC and the Python program can display the data. Note, however that you won't be "using ADS1X15 in Python code" - that will happen in Arduino code.

For communication between your Arduino and Python this Simple nRF24L01+ Tutorial should help get you started.

...R



Two or three hours spent thinking and reading documentation solves most programming problems.

pax_electronica

In the link further down, there is a "Reading Analog Inputs" example that shows how to access the analog pins on an UNO using Python from a PC. That is what I thought to be good enough, if only the AD converter has a higher resolution.

I have bookmarked your link. It is very interesting. The ADS1x15 runs well on UNO. Having it sending data to PC is certainly a good choice. Another is just upgrade to a Raspberry Pi, or a third choice is to write some code to make ADS1x15 such that it works more or less like analog pins on a UNO. What I want to find out is the feasibility of the last choice.




Power_Broker

#5
Nov 25, 2019, 09:15 pm Last Edit: Nov 25, 2019, 09:17 pm by Power_Broker
You know that imports are case sensitive, right?

Try:
Code: [Select]

import Adafruit_ADS1x15.ADS1115 as ADS
from Adafruit_ADS1x15.analog_in import AnalogIn
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

Power_Broker

I'm looking at Adafruit_ADS1x15 and I can't find the module "analog_in". Where are you getting "analog_in" from?
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

pax_electronica

The code segment is from here: https://circuitpython.readthedocs.io/projects/ads1x15/en/latest/examples.html.

The FAQ section of CircuitPython has the following:

Q: Can AVRs such as ATmega328 or ATmega2560 run CircuitPython?

A: No.


see: https://learn.adafruit.com/welcome-to-circuitpython/frequently-asked-questions

So that is a dead end.

Robin2

The ADS1x15 runs well on UNO.

[....]


 or a third choice is to write some code to make ADS1x15 such that it works more or less like analog pins on a UNO
In my mind those two are the same thing. What have you in mind that makes them different?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

pax_electronica

#9
Nov 25, 2019, 11:59 pm Last Edit: Nov 26, 2019, 12:22 am by pax_electronica
I apologize for my lack of knowledge on Arduino. I have been eyeing it for sometime but wasn't able to get to it.

Based on my very limited understanding, I find Arduino generally "hard to control", with its loop and delays. I want to have the entire system controlled from a proper computer, and having it tell the Arduino to perform simple tasks. In this case, I want to run the ADS1x15 from a PC using Python, not on an Arduino with C (or Python). The question is whether that is feasible, and if so, how.

I am aware that there are event based Arduino packages. They might help with controlling Arduino. But they are, again, all done in the Arduino, with the dinky processor.


Power_Broker

I mean, RPi has I2C - you can connect the ACD directly to it and cut out the Arduino entirely if you want
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

pax_electronica

The ESP32 is yet another choice. It looks very attractive: as cheap as Arduino if not cheaper, but much more powerful. CircuitPython FAQ has a question "Is ESP8266 or ESP32 supported in CircuitPython? Why not?". The answer is ESP8266 support was dropped, but did not mention ESP32. They are perhaps being intentionally vague.

Robin2

Based on my very limited understanding, I find Arduino generally "hard to control", with its loop and delays.
Most people (me included) would advise you not to use delay()s in your Arduino programs. The loop() function is just a convenience to get things to repeat - for example to read the next message from Python.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up