Show Posts
Pages: [1]
1  Development / Other Software Development / Re: New function in library on: March 11, 2011, 03:53:17 am
Hey,

but the time changes and that code would'nt work all time (for example, when hour is 10, 11, ...)?

Best regards
2  Development / Other Software Development / Re: New function in library on: March 08, 2011, 02:41:35 am
Thank you for reply.

I still think, it has something to do with my wrong modification to lib. If I comment out my added lines (print(int n)), the above code writes II or III to LCD, where there is supposed to be a number.

Best regards
3  Development / Other Software Development / Re: New function in library on: March 07, 2011, 03:39:11 pm
When you say "it doesn't work", what do you mean?

Hey,

when I said it doesn't work, I ment this:


On first row, there is time, printed with itoa function (integers converted to string with itoa and then printed as "print(char s*), in second line, it is writen with function, that I added to lib (as mentioned in my first post).
The code, used in video:
Code:
#include <bv4618.h>
#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h> // written by  mattt on the Arduino forum and molcdfied by D. Sjunnesson

BV4618 lcd(0x31); // 0x62 I2C address (8 bit)

void setup()
{
  Serial.begin(9600);
  lcd.clear(); // clear screen
  lcd.setdisplay(4,20); // set up lcdsplay geometry
}

void loop()
{
  int hour, minute, second;
  hour = RTC.get(DS1307_HR,true);  //This is in military time  [0,23]
  minute = RTC.get(DS1307_MIN,false);
  second = RTC.get(DS1307_SEC,false);

  char hour_str[4]; // Define as a string
  char minute_str[4];
  char second_str[4];
  lcd.setCursor(1,1);  
 
  if(hour < 10){
    lcd.print("0");
  }
  lcd.print(itoa (hour, hour_str, 10)); //convert integer hour to string hour_str and print it on LCD
  lcd.print(':');
  if(minute < 10){
    lcd.print("0");
  }
  lcd.print(itoa (minute, minute_str, 10));
  lcd.print(':');
  if(second < 10){
    lcd.print("0");
  }
  lcd.print(itoa (second, second_str, 10));
  lcd.setCursor(1,11);

 /*************** PRINTS TIME "INTEGER" *****************/
   lcd.setCursor(2,1);  
  if(hour < 10){
    lcd.print("0");
  }
  lcd.print(hour);
  lcd.print(':');
  if(minute < 10){
    lcd.print("0");
  }
  lcd.print(minute);
  lcd.print(':');
  if(second < 10){
    lcd.print("0");
  }
  lcd.print(second);
}

It looks like you are using he code straight out of print(char).  In that case it will likely take the low-order byte of the integer and print it as a character.  I don't think that what you intend.  You probably want to use itoa(n) and use the look from print(char *) to print the digits of the number.

Its complicated for me (I guess you already noticed, I'm very new to coding smiley).
I would like to add function to lib that when I write:
Code:
int hour
lcd.print(hour); //or maybe lcd.print(hour, DEC); ???
there would be the correct hour on the display smiley

Any more help would be much appreciated.
Thank you in advance.


4  Development / Other Software Development / New function in library on: March 06, 2011, 01:56:51 pm
Hey guys.

I'm trying to add a function to a library for I2C LCD controller.

Now, there are two functions for writing on LCD: for printing strings and for printing single chars, but none for printing integers or decimal numbers. I know, that I can convert integers with command itoa to strings, but I would like to implement function for printing them directly, if possible.

For printing chars and strings, here is the code from lib:
BV4618.cpp:
Code:
// sends char
void BV4618::print(char c){
  Wire.beginTransmission(_i2adr);
  Wire.send(c);
  Wire.endTransmission();
}
// sends string
void BV4618::print(char *s){
  char *sp=s; 
    Wire.beginTransmission(_i2adr);
    // send *s as bytes of date
    while(*sp)
      Wire.send(*(sp++));
    Wire.endTransmission();
}

BV4618.h:
Code:
void print(char c);
void print(char *s);



For printing integers, I tried to use code from Print.h and changed it a bit
BV4618.cpp:
Code:
void BV4618::print(int n){
  Wire.beginTransmission(_i2adr);
  Wire.send(n);
  Wire.endTransmission();
}
BV4618.h:
Code:
void print(int n);

but that doesn't work smiley-sad

Any help from more experienced coders would be much appreciated.
Thank you in advance.
5  Using Arduino / Displays / Re: ByVac 4618 I2C LCD/keypad controller on: March 03, 2011, 03:46:38 pm
Guess what?
It's working without a int pin smiley
I didn't wire it up using 2 pull up resistors.
With them it works smiley
6  Using Arduino / Displays / Re: ByVac 4618 I2C LCD/keypad controller on: March 03, 2011, 03:29:32 pm
Hey,

got it (at least for the puts part).

You can convert integer to a string with itoa command.

For my example, here is a working code:

Code:
int hour;
hour = RTC.get(DS1307_HR,true);
char hour_str[4]; // Define as a string (4 bytes)
itoa (hour, hour_str, 10); //convert integer to string
di.puts(hour_str); //print string on LCD

It can be also used like this:
Code:
int hour;
hour = RTC.get(DS1307_HR,true);
char hour_str[4]; // Define as a string (4 bytes)
di.puts(itoa (hour, hour_str, 10)); //convert integer to string and print string on LCD

I'm still scratching my head bout using keypad without interupt pin.
Any help is appreciated
Bostjan
7  Using Arduino / Displays / ByVac 4618 I2C LCD/keypad controller on: March 03, 2011, 03:46:06 am
Hello.

I bought Byvacs new LCD and keypad I2C conbtroller http://www.byvac.com/bv3/index.php?route=product/product&path=41_42&product_id=100 .
Datasheet: http://www.byvac.co.uk/downloads/datasheets/BV4618%20Datasheet.pdf
UserGuide: http://www.byvac.co.uk/downloads/BV4618/BV4618%20User%20Guide.pdf
ArduinoLib: http://www.byvac.co.uk/downloads/BV4618/BV4618_lcdkey_arduino_lib.zip

I wired it all up (4x20 LCD + 4x4 keypad) and loaded their example code and it all works (if I use int pin 9 as interrupt), but doesn't without int pin, although in userguide says it should (but the proc and i2c bus will be more though loaded, which I don't mind). Any ideas about that?

Though the working example code I would like to print some more stuff on LCD...for example time from RTC.

I tried the following code:
Code:
  di.puts("Hour Test"); //Prints line on LCD
  int hour;
  hour = RTC.get(DS1307_HR,true);
  di.puts(hour);
  Serial.print(hour); //for test

It prints "Hour Tets" on LCD, and nothing else. On serial monitor I get the correct hour time.
I guess it has something to do with statement in Userguide about "puts" function, that says: "
Sends a string to the i2c bus. The string must be a string, i.e. null
terminated."

I guess, I should somehow convert "hour" to text. Any ideas, how to do that?

This library is a bit hard to read for me... I saw nicely writen lib for Byvac 4218, but have no idea, how to correct it to work with my controller.

Thank you for help in advance.
Bostjan

8  Forum 2005-2010 (read only) / Syntax & Programs / Re: LCD keypad menu help on: January 01, 2010, 01:15:37 pm
Hey guys.

My goal is the same, as delis. I'm trying to build reef aquarium controler. I bought the Freduino and lcd keypad shield from nuelectronics.

MY goal is something like this:
When you turn it on, I would like to write on display:

Temp: xx°C       TIME (time in 24h format
pH: xx               DATE (dd.mm.yy)

For time, I will use Software Date Time library.

Then when you press menu button, you get:

1st level:        <  pH calibration >       ;      <  temp  >    ;    <  Lights  >  ;   <Pumps>  ;
Your moving thrue menus with left or right button. If you press select, you run the program or go to sublevel:

2nd level : pH calibration: (run program for calibration)
                temp: < low >  ;  <  high1  > ;  <high2>(if I press select button on low, then I can insert the low temperature -> when to turn on the heater (with relay switch); if i press select on high1, I can enter the temp, in which the heater is turned off; in high2, i enter the temperature, in whict the cooling ventilator is turned on )
                lights: <manual switch>; <timers>; (I have four pairs of lights: in manual switch sublevel, there would bi option tu turn off or on those lights; in timers, there would be option to set the on and off time for every pair of lights)
                pumps: <feeding mode>; <manual switch>; <water change> ; (feeding mode is a program, the shuts of the 2 main pumps for a few minutes; in manual switch sub level, there would be options for turning off or on all 5 pumps in the system; water change is a program, thet automatically turns of all 5 pumps, until i press the set button again)

I must say, I'm a beginner in elctronics and programing. So I started learning and found this great thread. Kiwix really did a great job on those menues. I also started to play with code for temperature.
I managed to print current temperature (dallas 1-wire sensor) and also for showing the temperature simultaneously on LCD screen:

Code:

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 14, 9, 4, 5, 6, 7);
#include <stdio.h>
#define TEMP_PIN 3

//create object to control an LCD.  
//number of lines in display=1

void getCurrentTemp(char *temp);

//Key message
int  adc_key_val[5] ={30, 150, 360, 535, 760 };
int NUM_KEYS = 5;
int adc_key_in;
int key=-1;
int oldkey=-1;

void setup() {
    // initial lcd display while initialize and pc detection
    lcd.clear();
    lcd.print(" Reefino 0.0.t  ");
    delay(2000);

   // initialize DS18B20 datapin
    digitalWrite(TEMP_PIN, LOW);
    pinMode(TEMP_PIN, INPUT);      // sets the digital pin as input (logic 1)

}

void loop() {

  char temp_string[10];
  adc_key_in = analogRead(0);    // read the value from the sensor  

 {
    delay(50);            // wait for debounce time
    adc_key_in = analogRead(0);    // read the value from the sensor  

    {                  
      getCurrentTemp(temp_string);
      lcd.clear();
      lcd.setCursor(0,1);
      lcd.print(temp_string);
    }
 }
}

// Convert ADC value to key number
int get_key(unsigned int input)
{
      int k;
          for (k = 0; k < NUM_KEYS; k++)
      {
            if (input < adc_key_val[k])
            {
    return k;
        }
      }
    if (k >= NUM_KEYS)
        k = -1;     // No valid key pressed
    return k;
}

void OneWireReset(int Pin)  // reset.  Should improve to act as a presence pulse
{
     digitalWrite(Pin, LOW);
     pinMode(Pin, OUTPUT); // bring low for 500 us
     delayMicroseconds(500);
     pinMode(Pin, INPUT);
     delayMicroseconds(500);
}

void OneWireOutByte(int Pin, byte d) // output byte d (least sig bit first).
{
   byte n;
   for(n=8; n!=0; n--)
   {
      if ((d & 0x01) == 1)  // test least sig bit
      {
         digitalWrite(Pin, LOW);
         pinMode(Pin, OUTPUT);
         delayMicroseconds(5);
         pinMode(Pin, INPUT);
         delayMicroseconds(60);
      }
      else
      {
         digitalWrite(Pin, LOW);
         pinMode(Pin, OUTPUT);
         delayMicroseconds(60);
         pinMode(Pin, INPUT);
      }
      d=d>>1; // now the next bit is in the least sig bit position.
   }
}
byte OneWireInByte(int Pin) // read byte, least sig byte first
{
    byte d, n, b;
    for (n=0; n<8; n++)
    {
        digitalWrite(Pin, LOW);
        pinMode(Pin, OUTPUT);
        delayMicroseconds(5);
        pinMode(Pin, INPUT);
        delayMicroseconds(5);
        b = digitalRead(Pin);
        delayMicroseconds(60);
        d = (d >> 1) | (b<<7); // shift d to right and insert b in most sig bit position
    }
    return(d);
}
void getCurrentTemp(char *temp)
{  
  int HighByte, LowByte, TReading, Tc_100, sign, whole, fract;

  OneWireReset(TEMP_PIN);
  OneWireOutByte(TEMP_PIN, 0xcc);
  OneWireOutByte(TEMP_PIN, 0x44); // perform temperature conversion, strong pullup for one sec

  OneWireReset(TEMP_PIN);
  OneWireOutByte(TEMP_PIN, 0xcc);
  OneWireOutByte(TEMP_PIN, 0xbe);

  LowByte = OneWireInByte(TEMP_PIN);
  HighByte = OneWireInByte(TEMP_PIN);
  TReading = (HighByte << 8) + LowByte;
  sign = TReading & 0x8000;  // test most sig bit
  if (sign) // negative
  {
    TReading = (TReading ^ 0xffff) + 1; // 2's comp
  }
  Tc_100 = (6 * TReading) + TReading / 4;    // multiply by (100 * 0.0625) or 6.25

  whole = Tc_100 / 100;  // separate off the whole and fractional portions
  fract = Tc_100 % 100;

      sprintf(temp, "%c%3d%c%2d", (sign==0)?'+':'-', whole, '.', fract);
}


When I tried to implement this code into kiwix code, all I did was fail smiley-sad
Would anybody be so nice and help me.
Thanky ou very much.
Best regards!
9  Forum 2005-2010 (read only) / Development / Re: Time Library added to Playground on: January 12, 2010, 05:14:42 pm
mem, thank you. It works now.

Cheers
10  Forum 2005-2010 (read only) / Development / Re: Time Library added to Playground on: January 12, 2010, 11:12:15 am
Hey mem.

I tried to use your code (from your last post) and the error I get is:
error: 'TimeElements' does not name a type In function 'void processSetTime()':

Any suggestions?
Thank you in advance
11  Forum 2005-2010 (read only) / Interfacing / Re: PH Probe Op Amp help on: January 23, 2011, 03:23:34 pm
Hi pubdc,

I'm also considering pH/ORP adapter from phidgets.
Do you have any code and wiring diagram for connecting this to arduino?

Thanky in advance
Pages: [1]