Thread Rating:
  • 2 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Show off your DIY and modified tools!
#31
This is nothing new, just trying to re-create some of #daromer's work to measure temps while getting an introduction to python and grafite grafana and influxdb.etc... (like 3 projects in one)

 

Kind of using http://diytechandrepairs.nu/create-your-...0-charger/ as a pattern, but I am using some recycled 2 wire thermistors and a MCP3008 10 bit ADC.

I wired it all up last Friday and worked on the programming the last week, then decided to replace the wiring (speaker wires) with a cat-5 cable. I tried really hard to get the cat-5 plug to fit in the back of the opus, but it is really tight so i decided to make the thermistor wires a pigtail.

Will be working on this project while I am waiting on parts for my bigger tester... good to dust off my DIY chops a bit.


Also working on measuring temps with an i2c module as well. I have to move all the thermistor wires around to work on the i2c,. The pushbutton is unused.

Here is the Python script for measuring temps using the MCP3008 ADC on a Raspberry Pi.
Code:
#!/usr/bin/env python
# This script will read a set of 10K thermocouples using a MCP3008 ADC on a Raspberry Pi running python
# Adapted from work by others... Adafruit Industries, Paul Chow and 4 or 5 others (URL's provided in comments). 
# For my needs, I merged their work  with some of mine to make this script that calculates temperature and creates a log file for up to 8 ADC ports.
# https://learn.adafruit.com/raspberry-pi-analog-to-digital-converters/mcp3008
# http://www.paulschow.com/2013/08/monitoring-temperatures-using-raspberry.html [basiclogmcp.py]
# ASCII Art Schematic added from Paul's web site
#
#
# +3.3V ---- 10K THERMISTOR --+-- 10K OHM RESISTOR ---- GROUND
#                 |
#                 |
#                 |
#            DIGITAL PIN on MCP3008 (the chip I am using)
#
# Pinout 
#
# MCP 3208 Pin          Pi GPIO Pin #    Pi Pin Name
# ==============        ===============  =============
# 16  VDD                 1              3.3 V
# 15  VREF                1              3.3 V
# 14  AGND                6              GND
# 13  CLK                23              GPIO11 SPI0_SCLK
# 12  DOUT               21              GPIO09 SPI0_MISO
# 11  DIN                19              GPIO10 SPI0_MOSI
# 10  CS                 24              GPIO08 CE0
#  9  DGND                6              GND
#
# A simple script to log data from the MCP3208
# Based off mcp3208.py

DEBUG = 0    # set DEBUG = 1 if you want to see values displayed as calculations are made 

import os
import math
import string
import time
from time import strftime      #dropped this in favor of using the logging library
import logging
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)

# uncomment to use weather.com for outside temp
# weather_com_result = pywapi.get_weather_from_weather_com('yourzipcodehere')
# you will also ned to install the libraries from https://code.google.com/archive/p/python-weather-api/
# import pywapi

######################################################################################################
# The library for initializing and IO for the MCP3008 is on Adafruit:
# https://learn.adafruit.com/raspberry-pi-analog-to-digital-converters
# follow the link for the MCP3008 SPI or the other I2C if thats what you have. I am using the MCP3008
######################################################################################################
# Simple example of reading the MCP3008 analog input channels and printing them all out.
# Author: Tony DiCola
# License: Public Domain
# Import SPI library (for hardware SPI) and MCP3008 library.

import RPi.GPIO as GPIO
GPIO.setwarnings(False)

# read SPI data from MCP3008 chip, 8 possible adc's (0 thru 7)
def readadc(adcnum, clockpin, mosipin, misopin, cspin):
        if ((adcnum > 7) or (adcnum < 0)):
                return -1
        GPIO.output(cspin, True)

        GPIO.output(clockpin, False)  # start clock low
        GPIO.output(cspin, False)     # bring CS low

        commandout = adcnum
        commandout |= 0x18  # start bit + single-ended bit
        commandout <<= 3    # we only need to send 5 bits here
        for i in range(5):
                if (commandout & 0x80):
                        GPIO.output(mosipin, True)
                else:
                        GPIO.output(mosipin, False)
                commandout <<= 1
                GPIO.output(clockpin, True)
                GPIO.output(clockpin, False)

        adcout = 0
        # read in one empty bit, one null bit and 10 ADC bits
        for i in range(12):
                GPIO.output(clockpin, True)
                GPIO.output(clockpin, False)
                adcout <<= 1
                if (GPIO.input(misopin)):
                        adcout |= 0x1

        GPIO.output(cspin, True)
        
        adcout >>= 1       # first bit is 'null' so drop it
        return adcout

# change these as desired - they're the pins connected from the
# SPI port on the ADC to the Cobbler
SPICLK = 18
SPIMISO = 23
SPIMOSI = 24
SPICS = 25

# set up the SPI interface pins
GPIO.setup(SPIMOSI, GPIO.OUT)
GPIO.setup(SPIMISO, GPIO.IN)
GPIO.setup(SPICLK, GPIO.OUT)
GPIO.setup(SPICS, GPIO.OUT)

# Set up logging
# https://stackoverflow.com/questions/15474095/writing-a-log-file-from-python-program
log = "ADC_temps.123017.log"
logging.basicConfig(filename=log,level=logging.DEBUG,format='%(asctime)s %(message)s', datefmt='"%Y-%m-%d %H:%M:%S",')
logging.info('============================================')
logging.info('Info: Logging started')

print(' ' * 23)
print('Reading MCP3008 values, press Ctrl-C to quit...')
print('Logging to: ')    #print the name of the log file
print(log)

# debug option to see if I can read  all ports on the ADC
if DEBUG == 1:
        print ('================================')
        adcout=readadc(0, 18, 24, 23, 25)
        print(adcout)
        adcout=readadc(1, 18, 24, 23, 25)
        print(adcout)
        adcout=readadc(2, 18, 24, 23, 25)
        print(adcout)
        adcout=readadc(3, 18, 24, 23, 25)
        print(adcout)
        adcout=readadc(4, 18, 24, 23, 25)
        print(adcout)  
        adcout=readadc(5, 18, 24, 23, 25)
        print(adcout)
        adcout=readadc(6, 18, 24, 23, 25)
        print(adcout)
        adcout=readadc(7, 18, 24, 23, 25)
        print(adcout)
        print ('================================')

# Print a column header for the screen.
print(' ')
print('|     Time    | {1:>4} | {2:>4} | {3:>4} | {4:>4} | '  .format(*range(8)))
#print('-' * 60)
#print('/n')
logging.info('Date-Time,OutTemp,Port1,port2,port3,port4')
logging.info('-' * 50)
logging.info(" ")


value=0
volts = 1 #     #initial values to prevent division by zero error
ohms = 1 #    #initial values to prevent division by zero error
lnohm = 0
temp = 0
tempc = 0
c2 = 0
t1 = 0
t2 = 0 

# Added an array to hold the temperature calculations before output
temps = [0]*10
values = [0]*10

# from http://raspberrypi.powersbrewery.com/project-8-temperature-sensing-thermistor/
# Create a function to convert a resistance reading from our
# thermistor to a temperature in Celsius which we convert to
# Fahrenheit and return to our main loop
def temperature_reading(R):
    B =  3250 # Thermistor constant from thermistor datasheet
    R0 = 10000.0 # Resistance of the thermistor being used
    t0 = 273.15 # 0 deg C in K
    t25 = t0 + 25.0 # 25 deg C in K
    # Steinhart-Hart equation
    inv_T = 1/t25 + 1/B * math.log(R/R0)
    T = (1/inv_T - t0) * 1
    return T * 9.0 / 5.0 + 32.0 # Convert C to F

# Main program loop.
while True:
        # Read the ADC channel values and calculate temps, log them
        # The read_adc function will get the value of the specified channel (0-7).
        #logging.warning('To do: log a warning message if the temperature is over a threshold')
        print('-' * 50)
        i = 0  #for i in range (0-3):
        while i <= 3: 
                value = readadc(i, 18, 24, 23, 25)
                values[i] = value
                #calculate the voltage
                volts = (value * (3.3 / 1024))   #GG_changed grouping
                if value == 0:
                        # cheating a bit to prevent division by zero later on
                        value = 880
                ohms = ((1024/value-1)*10000) #calculate the ohms of the thermististor
                t = temperature_reading(ohms)
                #output to log and screen
                if DEBUG == 1:
                        print(value)
                        print(volts)
                        print(ohms)
                        print("Port %i ADC reading is: %5.2f" % (i, value))
                        print("Port %i temperature is: %5.2f" % (i, t))
                        logging.info('5.2%f' % t)  #write to log
                temps[i] = t
                i = i+1   #increment port number 
                if i == 4:                # call for print and log
                        print('%s,%6.2f,%6.2f,%6.2f,%6.2f' % (strftime("%D-%H:%M"), temps[0],temps[1],temps[2],temps[3]))
                        logging.info('%6.2f,%6.2f,%6.2f,%6.2f' % (temps[0],temps[1],temps[2],temps[3]))#write to log
                        # logging.info('%5.2f,%5.2f,%5.2f,%5.2f' % (values[0],values[1],values[2],values[3])) #write to log
                        time.sleep(2)     # Pause, then repeat the while true loop over and over again...
                        i = 0             # keep the while loop going
                        
GPIO.cleanup()     #outta here.

        

... and here is an example log file written to the SD card.
Code:
"2017-12-31 18:41:56", ============================================
"2017-12-31 18:41:56", Info: Logging started
"2017-12-31 18:41:56", Date-Time,OutTemp,Port1,port2,port3,port4
"2017-12-31 18:41:56", --------------------------------------------
"2017-12-31 18:41:56",  
"2017-12-31 18:41:56",  67.52, 67.90, 66.96, 67.52
"2017-12-31 18:41:58",  67.52, 67.34, 66.96, 67.52
"2017-12-31 18:42:00",  67.52, 68.09, 66.96, 67.52
"2017-12-31 18:42:02",  67.52, 68.09, 66.96, 67.71
"2017-12-31 18:42:04",  67.52, 68.09, 66.96, 67.71
"2017-12-31 18:42:06",  67.52, 68.09, 66.96, 67.71

Now working on getting the script to log temperature data to InfluxDB using Telegraf... its not really clear to me yet, so I am reading about the line protocol and how to get data into the database... 

Regards,
Gary
daromer and rebelrider.mike like this post
Regards,
Gary G.

Working on a 32 port #FCDS
Testing on 8 ports now... logging to Influx/Grafana

#32
Finally got all the code working ! Hallelujah !

Since I am not a programmer by trade and I had zero experience with Python, Influx, Grafana, and GPIO on the Pi it was a real learning experience.

I would never have made this effort if @daromer had not shared his work on the Pi3 and his solar management dashboard, but that was so cool I had to try it myself.  

Still having some discrepancies in the dashboard, but the data is making it from the recycled thermistors in the Opus through an ADC chip to the Pi running Debian Stretch and my collection script in Python 2.7 writing by Json to Influxdb v1.2 and being reported by Grafana v4.3 or something like that.



This is a building block to get me going on dashboards and databases for my tester build project
Korishan, mormor1971, rebelrider.mike like this post
Regards,
Gary G.

Working on a 32 port #FCDS
Testing on 8 ports now... logging to Influx/Grafana

#33
I already posted this in a different section, but I upgraded my Snap-On NiCad impact gun to lithium using 5S1P Samsung 25R cells.

On one test, reversing wheel lugs at 140 pound feet, it had a a max wattage of 712 watts / 41 amps peak.

Pictures and mods here:
https://secondlifestorage.com/t-Converte...to-Lithium

I like this thread... I add my other projects to it as well.
mormor1971 and rebelrider.mike like this post
#34
It's been 8 months since last update to this thread

Anyone have anything new to add?


Who read this thread?
100 User(s) read this thread:
hbpowerwall (12-08-2018, 04:45 AM), AZ_Tekkie (10-07-2017, 05:14 AM), daromer (01-24-2018, 01:53 PM), Sean (11-23-2018, 09:16 PM), mike (11-23-2018, 04:27 PM), 18650Shrink (08-08-2017, 11:46 PM), PaulKennett (08-18-2017, 01:43 AM), Lux_Gamer (01-28-2018, 01:18 PM), owitte (03-05-2018, 10:26 PM), opus40 (01-28-2018, 09:25 PM), Majorphill (01-24-2018, 11:35 AM), ruby2 (08-31-2017, 06:32 AM), Korishan (11-23-2018, 11:12 PM), A + A (09-21-2017, 11:58 AM), PAF (11-23-2018, 02:20 PM), Wattsup (08-11-2017, 10:05 PM), BobinTN (09-10-2017, 01:31 PM), Alec_J (09-17-2017, 04:36 PM), Mike C (09-11-2017, 07:44 AM), jdeadman (11-23-2018, 02:55 PM), monsted (09-28-2017, 04:26 PM), 2146 (01-24-2018, 08:28 PM), wim (03-06-2018, 06:41 AM), frnandu (10-25-2017, 10:05 PM), typ49 (09-19-2017, 07:10 AM), The-J-Man (05-17-2018, 12:17 PM), Robert Baumer (09-10-2017, 09:10 AM), Jeremy Choy (09-21-2017, 05:28 PM), 1958 greyhound (08-27-2017, 09:23 AM), Abarth595 (09-17-2017, 06:30 PM), kktuo (10-25-2017, 10:23 PM), rebelrider.mike (11-26-2018, 10:17 PM), kaits31 (08-26-2017, 07:04 PM), watts-on (11-24-2018, 09:44 AM), jesusangel (12-31-2017, 10:51 AM), BamBamsBatteries (08-13-2017, 12:41 AM), Daggerzz (08-27-2017, 10:53 PM), Hanssing (10-26-2017, 04:19 AM), Mark Daniel Olsen (12-30-2017, 11:53 AM), Joost2 (10-26-2017, 07:36 PM), kazbach (08-15-2017, 06:40 PM), Davel (10-28-2017, 11:41 PM), Stefaan De Ridder (11-23-2018, 01:59 PM), GBPhoto (09-30-2017, 05:24 PM), TomTinkerDIY (08-09-2017, 05:54 AM), Chiptosser (05-01-2018, 08:02 PM), Inverted 18650 (08-15-2017, 04:16 AM), BlueSwordM (11-23-2018, 08:59 PM), SolarWind (09-02-2017, 08:44 PM), brafi (10-24-2017, 08:10 AM), Erik Smith (08-18-2017, 11:26 PM), Terry (09-08-2017, 10:41 AM), Eric Koshinsky (08-16-2017, 12:54 AM), KtB (09-17-2017, 06:24 PM), Pyro (08-16-2017, 02:25 AM), JustMeTMC (08-16-2017, 03:53 AM), ivnz (07-29-2018, 01:51 AM), iceisfun (08-22-2017, 03:46 PM), Geek (11-24-2018, 06:17 AM), mike98 (08-26-2017, 03:38 PM), electricJolt (08-21-2017, 02:15 AM), TAGG (09-18-2017, 12:05 AM), BeastyNZ (12-30-2017, 08:00 PM), Jon (03-06-2018, 06:36 AM), Steve Kopesky (08-24-2017, 10:29 PM), mr_hypno (01-29-2018, 09:18 PM), floydR (03-13-2018, 11:44 AM), SimonW (09-26-2017, 04:53 AM), DarkRaven (09-17-2017, 06:13 PM), Gerard Achternaam (10-26-2017, 09:05 AM), nautal (09-18-2017, 11:47 PM), mashiweirk (11-26-2017, 01:00 AM), zag2me (09-28-2017, 08:27 AM), ChrisD5710 (10-07-2017, 12:18 PM), davidpesce (09-19-2017, 11:51 PM), aflecha (09-18-2017, 01:44 AM), WallBender (10-18-2017, 09:01 PM), mormor1971 (03-18-2018, 10:44 AM), Tostaki (10-30-2017, 04:06 PM), howiegrapek (10-26-2017, 01:28 AM), slimf (10-31-2017, 12:53 PM), Jason.T.Keenan (10-18-2017, 04:54 AM), dougm352 (10-12-2017, 01:13 PM), Stephen_Bartholomew (10-21-2017, 09:09 PM), cristof (01-24-2018, 08:03 AM), WardenCommader (10-24-2017, 01:31 PM), Oderus420 (01-24-2018, 01:21 PM), Oz18650 (10-08-2017, 08:57 AM), accoelho (10-26-2017, 06:47 AM), neurocis (01-25-2018, 03:56 AM), Dragosh Shescu (03-16-2018, 02:03 PM), alt.energy.nerd (10-11-2017, 02:17 AM), revolting (10-30-2017, 04:48 PM), timhester81 (10-22-2017, 02:50 AM), gtimo77 (10-29-2017, 05:48 PM), OctavioMaia (10-16-2017, 10:31 PM), paz45 (10-18-2017, 12:50 PM), Everythings-stuck-together (11-08-2017, 02:43 AM), revbryce (10-26-2017, 08:57 PM), CarelHassink (10-22-2017, 01:32 PM)

Forum Jump:


Users browsing this thread: 2 Guest(s)