Spike Brewing 12.5 Conical Fermenter Giveaway!

Home Brew Forums > Home Brewing Beer > DIY Projects > TeensyPi Networked Temperature Controller

Reply
 
LinkBack Thread Tools
Old 03-22-2013, 12:48 AM   #251
jimmayhugh
Turgid Member
HBT_LIFETIMESUPPORTER.png
Feedback Score: 0 reviews
 
jimmayhugh's Avatar
Recipes 
 
Join Date: Feb 2011
Location: Las Vegas, NV
Posts: 577
Liked 46 Times on 41 Posts
Likes Given: 2

Default

Quote:
Originally Posted by helibrewer View Post
Anyone else had issues with ActionDataWithMySQL.php not assigning the chip name correctly to an action? The temp value is correct but the name isn't. The chip names are all correct in the database and they are available in the dropdown.
You can put "echo" commands to output the results of the database queries to the webpage to see if the problem lies with the query result, that may help to figure out the problem.
jimmayhugh is offline
 
Reply With Quote Quick reply to this message
Old 03-22-2013, 12:49 AM   #252
jimmayhugh
Turgid Member
HBT_LIFETIMESUPPORTER.png
Feedback Score: 0 reviews
 
jimmayhugh's Avatar
Recipes 
 
Join Date: Feb 2011
Location: Las Vegas, NV
Posts: 577
Liked 46 Times on 41 Posts
Likes Given: 2

Default

Quote:
Originally Posted by redbenn View Post
@jimmayhugh are you still tweaking your board layout?
Yup, got the latest version coming to me now via China Post
jimmayhugh is offline
 
Reply With Quote Quick reply to this message
Old 03-22-2013, 02:50 PM   #253
redbenn
Feedback Score: 0 reviews
Recipes 
 
Join Date: Dec 2009
Location: Chicago
Posts: 133
Liked 3 Times on 3 Posts

Default

Quote:
Originally Posted by jimmayhugh View Post
I'm using python code ( ugh ) right now to run them, and I'm looking for a "C" library for the RPi, to make it a little easier to integrate with the php. So far no luck, but the wiringPi library looks promising.
Do you have the python code on your GitHub?
__________________
redbenn is offline
 
Reply With Quote Quick reply to this message
Old 03-22-2013, 05:46 PM   #254
jimmayhugh
Turgid Member
HBT_LIFETIMESUPPORTER.png
Feedback Score: 0 reviews
 
jimmayhugh's Avatar
Recipes 
 
Join Date: Feb 2011
Location: Las Vegas, NV
Posts: 577
Liked 46 Times on 41 Posts
Likes Given: 2

Default

Quote:
Originally Posted by redbenn View Post
Do you have the python code on your GitHub?
No, I'm using the Adafruit library and this test code:
Code:
#!/usr/bin/python

from time import sleep
from Adafruit_I2C import Adafruit_I2C
from Adafruit_MCP230xx import Adafruit_MCP230XX
from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate

import smbus
import socket,os
import StringIO
import csv
import socket
import MySQLdb as mdb
import sys


# connect to the database
con = None
lcdinfo = []
tpID = 0
tpTempAddr = 1
tpTcAddr = 2
tpThAddr = 3
tpLCD = 4
tpRGB = 5

try:
    con = mdb.connect('localhost', 'teensypi', 'teensypi', 'teensypi')
    cur = con.cursor()
    cur2 = con.cursor()
    cur.execute("SELECT id, tempAddr, tcAddr, thAddr, lcd, rgb FROM action WHERE lcd>0")
    numrows = int(cur.rowcount)
#    rows = cur.fetchall()
#    print numrows
    for x in range(0, numrows):
        row = cur.fetchone()
        lcdinfo.append([])
#        print row
        lcdinfo[x].append(row[tpID])
#        print lcdinfo[x][0]
        cur2.execute("SELECT name FROM chipNames where address = %s",(row[1]))
        lcdinfo[x].append(cur2.fetchone())
#        print lcdinfo[x][1][0]
#        print lcdinfo[x][1][0].center(20, ' ')
        cur2.execute("SELECT name FROM chipNames where address = %s",(row[2]))
        lcdinfo[x].append(cur2.fetchone())
#        print lcdinfo[x][2]
        cur2.execute("SELECT name FROM chipNames where address = %s",(row[3]))
        lcdinfo[x].append(cur2.fetchone())
#        print lcdinfo[x][3]
        lcdinfo[x].append(int(row[tpLCD]))
#        print lcdinfo[x][4]
        lcdinfo[x].append(int(row[tpRGB]))
#        print lcdinfo[x][tpRGB]
        
except mdb.Error, e:
  
    print "Error %d: %s" % (e.args[0], e.args[1])
    sys.exit(1)

finally:
    
    if con:
        con.close()

# initialize the LCD plate(s)
# use busnum = 0 for raspi version 1 (256MB) and busnum = 1 for version 2

lcd = []

for x in range(0,numrows):
    lcd.append([])
    lcd[x] = Adafruit_CharLCDPlate(busnum = 0, address=(lcdinfo[x][4]))
    lcd[x].begin(20, 4)
# clear display
    lcd[x].clear()
    lcd[x].setCursor(0, 0)
    lcd[x].message(((lcdinfo[x][tpTempAddr])[0])[0:20].center(20, ' '))
    lcd[x].setCursor(0,1)
    lcd[x].message("Temperature: ")
    lcd[x].setCursor(0,2)
    lcd[x].message((lcdinfo[x][tpTcAddr])[0])
    lcd[x].message(": ")
    lcd[x].setCursor(0,3)
    lcd[x].message((lcdinfo[x][tpThAddr])[0])
    lcd[x].message(": ")
# first loop, just changes the color
while 1:
#    sleep(.5)
    s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    s.connect("/tmp/teensypi")
    s.send('C\n')
    data = s.recv(1024)
    s.close()

    for x in range(0,numrows):
        splitActionArray = data.split(';', lcdinfo[x][0])
        actionItem = splitActionArray[lcdinfo[x][tpID]]
#        print actionItem
        splitActionItem = actionItem.split(',')
        lcd[x].setCursor(17,1)
        lcd[x].message(splitActionItem[1])
        lcd[x].setCursor(16,2)
        if lcdinfo[x][tpRGB] == 0:
          lcd[x].backlight(lcd[x].RED)          
        if splitActionItem[2] == 'F':
          lcd[x].message(" OFF")
        else:
          lcd[x].message(" ON ")
          if lcdinfo[x][tpRGB] == 1:
            lcd[x].backlight(lcd[x].BLUE)
        lcd[x].setCursor(16,3)     
        if splitActionItem[3] == 'F':
          lcd[x].message(" OFF")
        else:
          lcd[x].message(" ON ")
          if lcdinfo[x][tpRGB] == 1:
              lcd[x].backlight(lcd[x].RED)
        if splitActionItem[2] == 'F' and splitActionItem[3] == 'F' and lcdinfo[x][tpRGB] == 1:
          lcd[x].backlight(lcd[x].GREEN)
jimmayhugh is offline
 
Reply With Quote Quick reply to this message
Old 03-22-2013, 06:33 PM   #255
redbenn
Feedback Score: 0 reviews
Recipes 
 
Join Date: Dec 2009
Location: Chicago
Posts: 133
Liked 3 Times on 3 Posts

Default

Quote:
Originally Posted by jimmayhugh View Post
No, I'm using the Adafruit library and this test code:
Code:
#!/usr/bin/python

from time import sleep
from Adafruit_I2C import Adafruit_I2C
from Adafruit_MCP230xx import Adafruit_MCP230XX
from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate

import smbus
import socket,os
import StringIO
import csv
import socket
import MySQLdb as mdb
import sys
did you need to install new python libraries?
__________________
redbenn is offline
 
Reply With Quote Quick reply to this message
Old 03-22-2013, 07:07 PM   #256
jimmayhugh
Turgid Member
HBT_LIFETIMESUPPORTER.png
Feedback Score: 0 reviews
 
jimmayhugh's Avatar
Recipes 
 
Join Date: Feb 2011
Location: Las Vegas, NV
Posts: 577
Liked 46 Times on 41 Posts
Likes Given: 2

Default

Quote:
Originally Posted by redbenn View Post
did you need to install new python libraries?
Get the Adafruit files here:
https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code,
go to the Adafruit_CharLCDPlate directory, put the code I provided into that directory, select the address of the LCD (if you're using an adafruit lcd plate. the address is 0x20) and then run the code as root.
__________________
TeensyNet Networked Controller
ButtCrack Brewery
And This Is Why We Drink...
jimmayhugh is offline
 
Reply With Quote Quick reply to this message
Old 03-22-2013, 07:23 PM   #257
redbenn
Feedback Score: 0 reviews
Recipes 
 
Join Date: Dec 2009
Location: Chicago
Posts: 133
Liked 3 Times on 3 Posts

Default

Quote:
Originally Posted by jimmayhugh View Post
Get the Adafruit files here:
https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code,
go to the Adafruit_CharLCDPlate directory, put the code I provided into that directory, select the address of the LCD (if you're using an adafruit lcd plate. the address is 0x20) and then run the code as root.
Ah, needed python-mysqldb library installed.
__________________
redbenn is offline
 
Reply With Quote Quick reply to this message
Old 03-22-2013, 07:45 PM   #258
redbenn
Feedback Score: 0 reviews
Recipes 
 
Join Date: Dec 2009
Location: Chicago
Posts: 133
Liked 3 Times on 3 Posts

Default

In case anyone missed it, Teensyduino 1.13 has been released.


Quote:
Teensyduino 1.13 has been released.

http://www.pjrc.com/teensy/td_download.html

For use without Arduino, see the sample makefile in hardware/teensy/cores/teensy3 after installing.

These are the changes since Teensyduino 1.12:


Support for Arduino 1.0.4
Fix Serial.write(0)
Turkish keyboard layout (Teensy 3.0)
Fix while(!Serial)
Fixes for ST7565 library (Teensy 3.0)
Add OctoWS2811 library
Update libraries: Keypad, Metro, OneWire, Ping, ST7565
__________________
redbenn is offline
 
Reply With Quote Quick reply to this message
Old 03-24-2013, 03:59 AM   #259
helibrewer
HBT_SUPPORTER.png
Feedback Score: 1 reviews
 
helibrewer's Avatar
Recipes 
 
Join Date: Nov 2011
Location: Santa Rosa, CA
Posts: 3,102
Liked 181 Times on 165 Posts
Likes Given: 39

Default

Quote:
Originally Posted by redbenn View Post
In case anyone missed it, Teensyduino 1.13 has been released.
Wow, that adds nice integration, no more separate environments.
__________________
Something is always fermenting....
"It's Bahl Hornin'"

Primary:
Brite Tank/Lagering:
Kegged: Hefeweizen, Chocolate Hazelnut Porter, Kumquat Saison, Tart Cherry Cider, Belgian Tripel, Maibock Bock, Ommegang Abbey Ale Clone, Belgian Golden Strong, German Pils (WLP830)
Bottled: Belgian Quad (Grand Reserve), Derangement (Belgian Dark Strong)
On Deck:
My Site: www.restlesscellars.com
helibrewer is online now
 
Reply With Quote Quick reply to this message
Old 03-24-2013, 06:10 PM   #260
jimmayhugh
Turgid Member
HBT_LIFETIMESUPPORTER.png
Feedback Score: 0 reviews
 
jimmayhugh's Avatar
Recipes 
 
Join Date: Feb 2011
Location: Las Vegas, NV
Posts: 577
Liked 46 Times on 41 Posts
Likes Given: 2

Default LCD Progress

I'm making some headway in getting the LCDs to work with the RPi

Not interested in causing a flame war of C,C++ vs. Python, I just don't want to have to learn another language.

I'm using the wiringPi Library as the basis for the code, and the board I'm currently using is my own version of the Adafruit RGB LCD Pi Plate.

I'm also using 4x20 LCDs, and am not yet implementing the extra switches. If you want to play along, follow the download and install instuctions, and then get this code:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <errno.h>

#include <wiringPi.h>
#include <lcd.h>

// MCP23S17 Registers

#define IOCON           0x0A

#define IODIRA          0x00
#define IPOLA           0x02
#define GPINTENA        0x04
#define DEFVALA         0x06
#define INTCONA         0x08
#define GPPUA           0x0C
#define INTFA           0x0E
#define INTCAPA         0x10
#define GPIOA           0x12
#define OLATA           0x14

#define IODIRB          0x01
#define IPOLB           0x03
#define GPINTENB        0x05
#define DEFVALB         0x07
#define INTCONB         0x09
#define GPPUB           0x0D
#define INTFB           0x0F
#define INTCAPB         0x11
#define GPIOB           0x13
#define OLATB           0x15

// Bits in the IOCON register

#define IOCON_BANK_MODE 0x80
#define IOCON_MIRROR    0x40
#define IOCON_SEQOP     0x20
#define IOCON_DISSLW    0x10
#define IOCON_HAEN      0x08
#define IOCON_ODR       0x04
#define IOCON_INTPOL    0x02
#define IOCON_UNUSED    0x01

// Default initialisation mode

// RGB Backlight Values for Adafruit Raspberry Pi RGB-LCD display
#define OFF     0x0
#define RED     0x01
#define GREEN   0x02
#define YELLOW  0x03
#define BLUE    0x04
#define VIOLET  0x05
#define TEAL    0x06
#define WHITE   0x07

#define RED_LED   0xBF
#define GREEN_LED 0x7F
//BLUE_LED is controlled by the state of bit 0 of oldval

#define TRUE 1
#define FALSE 0

int x, y, xio, fd2, oldval, rows, cols, isRGB;
char *color;

void lcd_pinMode(int pin, int mode);
void lcd_digitalWrite(int pin, int value);

int main (void)
{  
  oldval = 0;
  rows = 4;
  cols = 20;
  isRGB = TRUE;
  i2cAddr = 0x20;

  if(isRGB == TRUE)
  {
    oldval &= 0xFE; // turn Blue_LED ON
    wiringPiI2CWriteReg8 (xio, OLATB, oldval) ;
    wiringPiI2CWriteReg8 (xio, OLATA, (GREEN_LED & RED_LED) ) ; //Turn RED_LED and GREEN_LED on
    color = "WHITE";
  }else{
    oldval |= 0x01; // turn Blue_LED OFF
    wiringPiI2CWriteReg8 (xio, OLATB, oldval) ;
    wiringPiI2CWriteReg8 (xio, OLATA, RED_LED) ; // Turn BACKLIGHT on
    color = "NO RGB";        
  }
  
  
  printf ("Raspberry Pi LCD test program\n") ;

  xio = wiringPiI2CSetup (i2cAddr);
  if (xio < 0){
    printf ("xio: Unable to initialise I2C: %s\n", strerror (errno));
    return 1;
  }
  wiringPiI2CWriteReg8 (xio, IOCON,  0x84) ;  // IOCON - set BANK bit
  wiringPiI2CWriteReg8 (xio, IODIRA, 0x3F) ;  // Port A -> Outputs
  wiringPiI2CWriteReg8 (xio, IODIRB, 0x00) ;  // Port B -> Outputs

  digitalWrite = lcd_digitalWrite;
  pinMode = lcd_pinMode;

  fd2 = lcdInit(rows, cols, 4, 7, 5, 4, 3, 2, 1, 0, 0, 0, 0);

  if(fd2 < 0){
    printf ("lcdInit 2 failed\n") ;
    return 1 ;
  }

  sleep (1) ;
  x = 0;
  y = 0;
  for(;;)
  {
    if (rows == 4)
    {
      lcdPosition (fd2, 0, 0) ; lcdPrintf (fd2, "  Adafruit %s   ", color) ;
      lcdPosition (fd2, 0, 1) ; lcdPuts (fd2, "    Raspberry Pi    ") ;
      lcdPosition (fd2, 0, 2) ; lcdPuts (fd2, " RGB-LCD Plate Test ") ;
      lcdPosition (fd2, 0, 3) ; lcdPrintf (fd2, "Iteration: %d", x) ;
    }else if(rows == 2){
      lcdPosition (fd2, 0, 0) ; lcdPrintf (fd2, "Adafruit %s ", color) ;
      lcdPosition (fd2, 0, 1) ; lcdPrintf (fd2, "Iteration:%d", x) ;    
    }
    x++;
    if(x % 10 == 0)
    {
      y++;
      if(y < 1 || y > 7){y = 1;}
      if(isRGB == TRUE)
      {
        switch(y)
        {
          case RED:
          {
            oldval |= 0x01; // turn Blue_LED OFF
            wiringPiI2CWriteReg8 (xio, OLATB, oldval) ;
            wiringPiI2CWriteReg8 (xio, OLATA, RED_LED) ; // Turn RED_LED on
            color = "RED";
            break;
          }
          
          case GREEN:
          {
            oldval |= 0x01; // turn Blue_LED OFF
            wiringPiI2CWriteReg8 (xio, OLATB, oldval) ;
            wiringPiI2CWriteReg8 (xio, OLATA, GREEN_LED) ; // Turn GREEN_LED on
            color = "GREEN";
            break;
          }
          
          case YELLOW:
          {
            oldval |= 0x01; // turn Blue_LED OFF
            wiringPiI2CWriteReg8 (xio, OLATB, oldval) ;
            wiringPiI2CWriteReg8 (xio, OLATA, (GREEN_LED & RED_LED) ) ; //Turn RED_LED and GREEN_LED on
            color = "YELLOW";
            break;
          }
          
          case BLUE:
          {
            oldval &= 0xFE; // turn Blue_LED ON
            wiringPiI2CWriteReg8 (xio, OLATB, oldval) ;
            wiringPiI2CWriteReg8 (xio, OLATA, (GREEN_LED | RED_LED) ) ; //Turn RED_LED and GREEN_LED off
            color = "BLUE";
            break;
          }
          
          case VIOLET:
          {
            oldval &= 0xFE; // turn Blue_LED ON
            wiringPiI2CWriteReg8 (xio, OLATB, oldval) ;
            wiringPiI2CWriteReg8 (xio, OLATA, RED_LED) ; //Turn RED_LED on
            color = "VIOLET";
            break;
          }
          
          case TEAL:
          {
            oldval &= 0xFE; // turn Blue_LED ON
            wiringPiI2CWriteReg8 (xio, OLATB, oldval) ;
            wiringPiI2CWriteReg8 (xio, OLATA, GREEN_LED ) ; //Turn GREEN_LED on
            color = "TEAL";
            break;
          }
          
          case WHITE:
          {
            oldval &= 0xFE; // turn Blue_LED ON
            wiringPiI2CWriteReg8 (xio, OLATB, oldval) ;
            wiringPiI2CWriteReg8 (xio, OLATA, (GREEN_LED & RED_LED) ) ; //Turn RED_LED and GREEN_LED on
            color = "WHITE";
            break;
          }
          
        }
        
      }else{
          oldval |= 0x01; // turn Blue_LED OFF
          wiringPiI2CWriteReg8 (xio, OLATB, oldval) ;
          wiringPiI2CWriteReg8 (xio, OLATA, RED_LED) ; // Turn BACKLIGHT on
          color = "NO RGB";        
      }
    }
  }

  return 0;
}

void lcd_pinMode(int pin, int mode){}

void lcd_digitalWrite(int pin, int value)
{
  oldval &= ~(1 << pin);
  oldval |= value << pin;
  wiringPiI2CWriteReg8 (xio, OLATB, oldval) ;
}
Set the i2cAddr (0x20 for the Adafruit Board), rows, cols, and isRGB variable to work with your display (if your LCD is not RGB, the code will use the RED_LED to enable the backlight) and compile it using:
Code:
sudo gcc -o ./i2c_lcd -I/usr/localinclude -L/usr/local/lib -lwiringPi i2c_lcd.c
Set the i2c_lcd file to executable with
Code:
sudo chmod 755 i2c_lcd
and run it:
Code:
sudo i2c_lcd
Now I can start getting serious.
__________________
TeensyNet Networked Controller
ButtCrack Brewery
And This Is Why We Drink...
jimmayhugh is offline
 
Reply With Quote Quick reply to this message
Reply


Quick Reply
Message:
Options
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Arduino - Networked Temperature Monitor jimmayhugh DIY Projects 81 01-27-2013 12:22 AM
Temperature Controller sy2088 Equipment/Sanitation 3 10-25-2012 06:28 PM
Lux Temperature Controller scoots DIY Projects 9 07-06-2012 01:38 PM
temperature controller from deas fridge - use as external controller on live fridge? BrewingChemist DIY Projects 1 05-22-2012 10:21 PM
Johnson Analog Temperature Controller Temperature Profile Coastarine Equipment/Sanitation 4 10-11-2010 03:58 PM