Commit b115329d authored by Rousseau Vincent's avatar Rousseau Vincent

Use ADS1115 python lib

parent e83b547d
FROM ros:kinetic-ros-core
# install ros tutorials packages
RUN apt-get update && apt-get install -y \
ros-kinetic-rosbridge-suite \
python-smbus python-pip \
ros-kinetic-rosbridge-suite python-pip \
&& rm -rf /var/lib/apt/lists/
RUN pip install adafruit-ads1x15
RUN pip install ADS1115
COPY . /app
......@@ -17,24 +17,12 @@ import rospy
from std_msgs.msg import Float32
import Adafruit_ADS1x15
import ADS1115 as ads1115_lib
class ADS1115(object):
def __init__(self, channel):
self.adc = Adafruit_ADS1x15.ADS1115()
# Choose a gain of 1 for reading voltages from 0 to 4.09V.
# Or pick a different gain to change the range of voltages that are read:
# - 2/3 = +/-6.144V
# - 1 = +/-4.096V
# - 2 = +/-2.048V
# - 4 = +/-1.024V
# - 8 = +/-0.512V
# - 16 = +/-0.256V
# See table 3 in the ADS1015/ADS1115 datasheet for more info on gain.
gain = 1
self.adc.start_adc(channel, gain=gain)
self.adc = ads1115_lib.ADS1115()
# Anonymous topic ?
self.pub = rospy.Publisher('chatter', Float32, queue_size=10)
......@@ -45,10 +33,7 @@ class ADS1115(object):
def timer_callback(self, event):
msg = Float32()
# Conversion in milli volt for gain 1
# https://github.com/kentegrate/rpi_drivers/blob/master/include/rpi_drivers/ads1115.hpp
# https://github.com/jrowberg/i2cdevlib/blob/master/Arduino/ADS1115/ADS1115.h
msg.data = self.adc.get_last_result()*0.125000
msg.data = self.adc.readADCSingleEnded()
rospy.loginfo('Publishing: "{0}"'.format(msg.data))
self.pub.publish(msg)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment