Show Posts
Pages: [1] 2 3 4
1  Using Arduino / Programming Questions / Re: Need help on loop function on: May 28, 2014, 05:52:07 pm
Quote
The loop function doesn't seem right where it reads the pots first which may have not changed
Why does that matter? If the value hasn't changed, and that matters, you could tell that by keeping track of that the value last time, and comparing that to the value this time. Use names like reading and currentState, to make it easy, like the examples show. Not. Use names like currReading and prevReading.

90% of the time the pots are going to be left alone on a position because they control the LED light strip lighting for the background of the bar. The only thing I was wondering was if I am constantly taking a reading and sending an update is it unnecessary and won't it cause unnecessary computing? Then again by doing a comparison it may end up equaling out to the same resources used.

Code:
// Interrupt is called once a millisecond, looks for any pulses from the sensor!
What's the flow rate? Is this really necessary? Isn't polling, which is far simpler, fast enough? Is a missed pulse all that critical? If so, why isn't the pule what triggers the interrupt?

I am unfamilliar with polling and even this set of code, I hacked it from someplace on the net for my useage. As far as flow rate I am not sure, its a standard kegerator so not pushing a ton of beer over long distances. Will a missed pulse be critical, no probably not. The end goal is to get an idea how much beer is in the keg.

Why do you have two identical functions to convert the thermistor reading to a temperature?

Code:
 double chestTemp;
  double towerTemp;
  double temp = ThermistorChest(analogRead(0));  // Read sensor on Pin A0
  double temp2 = ThermistorTower(analogRead(1));  // Read sensor on Pin A1
So, what the heck are chestTemp and towerTemp for? temp and temp2 are rather stupid names. The temperatures are in C, so the names should reflect that. Even better, though, is to convert the raw reading to a temperature in F in the function, so you don;t need 4 temperature variables, with values in two different units.

Good catch on the two identical functions... I don't know why I did that. I will fix the temperature functions because yes all I need is the F. Thanks!

It seems to me that you could show both temperatures and the flow on the LCD at one time, simplifying the interface. Showing the same value (flow in ounces) on both lines of the LCD is pointless, isn't it?

I haven't added in the second flowsensor in the code as of yet because I was bench testing with one. I will add it in now. I have upgraded from a 16x2 LCD to a 20x4 LCD so I will play with the interface a bit.

I am thinking of having it say something generic as default and when the button is pressed it scrolls through the temps and then to ounces poured. Then as soon as a beer starts pouring it displays that line. I also am going to implement an EEPROM chip (I have it on hand) to store the flow data so upon a reset it has the ounces saved.
2  Using Arduino / Programming Questions / Re: Need help on loop function on: May 28, 2014, 05:33:24 pm
What exactly is your problem?
You can not tell if something has changed until you read it. At which point you can tell if it has changed. One technique is to do the stuff you would have done when it has changed even if it has not. Depending on what you are doing this is perfectly normal. However sometimes this technique is not sutiable as the resulting behavoure is not what you want.

As of right now there is no error in my code. I am just trying to learn by critique.
3  Using Arduino / Programming Questions / Need help on loop function on: May 27, 2014, 09:00:01 pm
A bit of background on what I am trying to do. I am trying to set up a very personalized kegerator monitoring system but wanted it to be 100% standalone and a set it and forget it setup unlike the kegbot and others out there.

This being said I have one java programming class under my belt and a few projects done but I still feel I have A LOT to learn.

Kegerator monitor system as well as RGB led strip controller.

Have:
2 - Thermistors one in tower and one in chest
3 - Pots controlling the RGB Led strip
1 - i2c 24LC256 EEPROM chip (NOTE: Not implemented in my code yet)
1 - i2c 20x4 LCD
1 -  Button (as of now)
2 - Digital Flow sensors (One implemented as of today)

Here is my code as it sits, what can I tweak before moving on? I am still learning the lingo so I appreciate the help. The loop function doesn't seem right where it reads the pots first which may have not changed and then goes to the button which may have not changed either...

Code:
#include <Wire.h>
#include <math.h>
#define FLOWSENSORPIN 7 // Flow Sensor #1
#define REDPIN 5
#define GREENPIN 6
#define BLUEPIN 3
#define REDPOT A1
#define GREENPOT A2
#define BLUEPOT A3

#include <LiquidCrystal_I2C.h>
// Get the LCD I2C Library here:
// https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
// Move any other LCD libraries to another folder or delete them
// See Library "Docs" folder for possible commands etc.

// set the LCD address to 0x20 for a 20 chars 4 line display
// Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

const int buttonPin = 8;
int buttonState = 0;

/*
Thermistor Connections:
Thermistor Pin 1 to +5v
Thermistor Pin 2 to Analog Pin 0
10k ohm resistor pin 1 to Analog Pin 0
10k ohm resistor pin 2 to Gnd
*/


// --- FLOWSENSOR --- //

// count how many pulses!
volatile uint16_t pulses = 0;
// track the state of the pulse pin
volatile uint8_t lastflowpinstate;
// you can try to keep time of how long it is between pulses
volatile uint32_t lastflowratetimer = 0;
// and use that to calculate a flow rate
volatile float flowrate;
// Interrupt is called once a millisecond, looks for any pulses from the sensor!
SIGNAL(TIMER0_COMPA_vect) {
  uint8_t x = digitalRead(FLOWSENSORPIN);
 
  if (x == lastflowpinstate) {
    lastflowratetimer++;
    return; // nothing changed!
  }
 
  if (x == HIGH) {
    //low to high transition!
    pulses++;
  }
  lastflowpinstate = x;
  flowrate = 1000.0;
  flowrate /= lastflowratetimer;  // in hertz
  lastflowratetimer = 0;
}

void useInterrupt(boolean v) {
  if (v) {
    // Timer0 is already used for millis() - we'll just interrupt somewhere
    // in the middle and call the "Compare A" function above
    OCR0A = 0xAF;
    TIMSK0 |= _BV(OCIE0A);
  } else {
    // do not call the interrupt function COMPA anymore
    TIMSK0 &= ~_BV(OCIE0A);
  }
}



void setup(void) {
 
// --- Start wire for EEPROM --- //
  Wire.begin();
  unsigned int address = 0;
 
// --- Set up LCD --- // 
  lcd.begin(20, 4);              // 20,4 for a 20x4 LCD.
  lcd.clear();                   // start with a blank screen
  lcd.setCursor(0,0);            // set cursor to column 0, row 0
 
// --- Flow sensor #1 --- //
  pinMode(FLOWSENSORPIN, INPUT);
  digitalWrite(FLOWSENSORPIN, HIGH);
  lastflowpinstate = digitalRead(FLOWSENSORPIN);
  useInterrupt(true);
 
// --- Set up buttons --- //
  pinMode(buttonPin, INPUT);
 
// --- Set up RGB output pins --- // 
  pinMode(REDPIN, OUTPUT);
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);
 
// --- Set up RGB potentiometers --- //
  pinMode(REDPOT, INPUT);
  pinMode(GREENPOT, INPUT);
  pinMode(BLUEPOT, INPUT);

}


// --- Thermistor #1 --- //
double ThermistorChest(int RawADC) { // conversion for chest thermistor
  double Temp;
  // See See http://en.wikipedia.org/wiki/Thermistor for explanation of formula
  Temp = log(((10240000/RawADC) - 10000));
  Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
  Temp = Temp - 273.15;           // Convert Kelvin to Celcius
  return Temp;
}

// --- Thermistor #2 --- //
double ThermistorTower(int RawADC) { // conversion for tower thermistor
  double Temp;
  // See See http://en.wikipedia.org/wiki/Thermistor for explanation of formula
  Temp = log(((10240000/RawADC) - 10000));
  Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
  Temp = Temp - 273.15;           // Convert Kelvin to Celcius
  return Temp;
}

void printTemp(void) {
  double chestTemp;
  double towerTemp;
  double temp = ThermistorChest(analogRead(0));  // Read sensor on Pin A0
  double temp2 = ThermistorTower(analogRead(1));  // Read sensor on Pin A1
 
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Chest: ");
  chestTemp = (temp * 1.8) + 32.0;    // Convert to Fahrenheit
  lcd.print(chestTemp);
  lcd.print((char)223);
  lcd.print("F");
 
  lcd.setCursor(0,1);
  lcd.print("Tower: ");
  towerTemp = (temp2 * 1.8) + 32.0;    // Convert to Fahrenheit
  lcd.print(towerTemp);
  lcd.print((char)223);
  lcd.print("F");
}

void printOunces(void) {
  float liters = pulses;
  liters /= 7.5;
  liters /= 60.0;

  float ounces;
  ounces = (liters * 33.8);
  lcd.setCursor(0, 0);
  lcd.print("Line 1 "); lcd.print(ounces); lcd.print(" Oz        ");
  lcd.setCursor(0, 1);
  lcd.print("Line 2 "); lcd.print(ounces); lcd.print(" Oz        ");
 
  delay(100);
}

void loop(void) {
 
// --- Whenever the RGB potentiometers are rotated they change colors --- // 
  int r, g, b;
  int rPot, gPot, bPot;
    analogWrite(REDPIN, analogRead(REDPOT)/4);  // Copy 10-bit input to 8-bit output
    analogWrite(GREENPIN, analogRead(GREENPOT)/4);  // Copy 10-bit input to 8-bit output
    analogWrite(BLUEPIN, analogRead(BLUEPOT)/4);  // Copy 10-bit input to 8-bit output
 
 
// --- Reading button. Unpressed displays temperatures from thermistor #1 and #2 while pressed displays ounces poured  --- // 
  buttonState = digitalRead(buttonPin);
 
  if (buttonState == LOW) {
    lcd.clear();
    printTemp();
  }
  else {
    lcd.clear();
    printOunces();
  }
  delay(1000);
}
4  Using Arduino / Networking, Protocols, and Devices / Re: i2c appears to not be reading anything. on: May 27, 2014, 07:32:55 pm
Ok I have an update. I pulled out my nifty shield to burn a new bootloader on a brand new atmega328 and swapped it out and everything works.  smiley-money

I swear this craps a PITA!

Next I will re-burn the bootloader on the original chip and see if it will now work.

Result - The original atmega328 DID NOT work after a fresh bootloader install.

5  Using Arduino / Networking, Protocols, and Devices / Re: i2c appears to not be reading anything. on: May 26, 2014, 04:35:28 pm
Ok tested as follows:

Checked power rails on both sides and they run the length of the breadboard.

Checked each wire for breaks. None found.

Checked for power at EEPROM Pin 8 VCC - +4.88Vdc
Pins 1-4 and 7 all 0Vdc as expected due to being on ground.
Pin 5 expected +5Vdc read +4.80Vdc
Pin 6 expected (unsure) read 0Vdc

Thoughts?
6  Using Arduino / Networking, Protocols, and Devices / Re: i2c appears to not be reading anything. on: May 26, 2014, 02:01:18 pm
Tested A4/A5 with blink and LED. Perfect.

Picture of current setup.
7  Using Arduino / Networking, Protocols, and Devices / Re: i2c appears to not be reading anything. on: May 26, 2014, 12:40:22 pm
Hack, checks out right. So weird..... Any other checks?
8  Using Arduino / Networking, Protocols, and Devices / Re: i2c appears to not be reading anything. on: May 26, 2014, 11:12:21 am
OMG.....  Ok I swear I haven't done this many dumb things in a row before!  smiley-eek-blue but unfortunately no change!

9  Using Arduino / Networking, Protocols, and Devices / Re: i2c appears to not be reading anything. on: May 26, 2014, 11:02:37 am
Ah dumb me... but still nothing once corrected.

10  Using Arduino / Networking, Protocols, and Devices / Re: i2c appears to not be reading anything. on: May 26, 2014, 10:00:16 am
Ok I completely reset, grabbed a new breadboard and all new wires and tested just the (different from yesterday aka new chip) eeprom chip and tested the LCD separate with both failing to read on the scanner.

Resistor's:

4.7k Ohm

Wires are:

Orange = GND's
Yellow(on eeprom) = +5Vdc
White = SCL
Yellow = SDA
Red = +5Vdc
Black = GND

I am thinking there is something I am screwing up consistently OR I have a hardware issue.

Can I manually jumper the LCD backpack if needed for a set address?

Lance
11  Using Arduino / Networking, Protocols, and Devices / Re: i2c appears to not be reading anything. on: May 25, 2014, 07:30:19 pm
Placed I tried 47k, 39k and 10k with no change...
12  Using Arduino / Networking, Protocols, and Devices / Re: i2c appears to not be reading anything. on: May 25, 2014, 06:37:33 pm
John,

No I don't, I was under the impression the Arduino did that (automatically or something). Whats a recommended size?
13  Using Arduino / Networking, Protocols, and Devices / i2c appears to not be reading anything. on: May 25, 2014, 05:41:28 pm
So I thought this would be very easy but it isn't working for me!

Very simple LCD with backpack purchased off of Ebay and 24lc256 EEPROM chips hooked up to the i2c bus and whats interesting is the scanner(s) I have tried doesn't find anything.

I uploaded another random sketch like the blink to verify the ATMEGA328 is ok and it was so I am at a loss and I have a feeling it is not the Arduino Uno's fault.

LCD      /    UNO
GND     ->  GND
+5VDC ->  VCC
SDA      ->  A4
SCL       ->  A5


Scanner sketches used:

Code:
#include <Wire.h>

void setup()
{
  Serial.begin(9600);
  Wire.begin();
  
  byte Return;
  
  Serial.println("Scanning I2C bus...");
  for(byte I2CAddress = 1; I2CAddress <= 127; I2CAddress++)
  {
    Serial.print("0x");
    if (I2CAddress<16)
      Serial.print("0");
    Serial.print(I2CAddress, HEX);
    Serial.print(" (");
    if (I2CAddress<10)
      Serial.print("  ");
    else if (I2CAddress<100)
      Serial.print(" ");
    Serial.print(I2CAddress);
    Serial.print("): ");
    
    Wire.beginTransmission(I2CAddress);
    Return = Wire.endTransmission();
    
    if (Return == 0)
      Serial.print("OK!");
    else
      Serial.print("   ");
      
    if (I2CAddress % 5)
      Serial.print("    ");
    else
      Serial.println();
  }
}

void loop() { }

Code:
// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011

#include <Wire.h>

void setup() {
  Serial.begin (115200);

  // Leonardo: wait for serial port to connect
  while (!Serial)
    {
    }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 8; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

Code:
// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>


void setup()
{
  Wire.begin();

  Serial.begin(9600);
  Serial.println("\nI2C Scanner");
}


void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknow error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);           // wait 5 seconds for next scan
}
14  Using Arduino / Programming Questions / Re: Servo.h missing on: October 11, 2013, 07:16:20 am
James, true but the library error is as unique to the Arduino.
In what way?  It works fine for me.  How are you "using" the Arduino on this PCduino thing?

Why do you say the PCduino has nothing to do with the Arduino?
Well, because, it doesn't.  It would be like posting a question about Windows 7 on forum that sells storm windows.  Just because someone uses a similar name, it doesn't mean they are related. 

PCduino has nothing to do with the Arduino project.

James on how I am using it is still very confusing to me. It appears it has GPIO pins like a raspberry pi but it ALSO labels them according the the Arduino pins for use with Arduino programming. I was under the impression I could upload a program in the Arduino IDE on the pcduino and compile and upload and it would work. Nay, I was wrong apparently. The Arduino IDE doesn't see the Servo.h library.


To the second part while the hardware is different the Arduino IDE and the code structure is the same as far as i understand it. Not wanting to get into a pissing match I had no other way of getting help with the programming questions.  smiley-eek-blue
15  Using Arduino / Programming Questions / Re: Servo.h missing on: October 11, 2013, 07:06:29 am
Not too sure, but trying to compile it on the arduino software compiles without any errors? I haven't used the PCduino before through, but it could be the way PCduino adds things? Where are you putting the servo.h file that you obtained?
and might be worth testing out changing
#include <Servo.h>
to
#include "Servo.h"

Trustnoone,

I have compiled it on the Arduino with no problem for a while now and I was curious to see how "easy" this PCduino is to use with the Arduino IDE and the Arduino labeld pins onboard. So far there is very little information and support out there since its so new.

The servo.h file doesn't seem to be a thing actually, upon investigating further I have found SoftwareServo.h (http://playground.arduino.cc/ComponentLib/servo) which I have tried to include but didn't work.

I will get a copy of the errors and try your suggestion of #include "Servo.h" this afternoon, I will post the results.
Pages: [1] 2 3 4