Go Down

Topic: i2c ebay display (Read 929 times) previous topic - next topic

bjhund

Sep 27, 2012, 09:45 pm Last Edit: Sep 27, 2012, 10:12 pm by bjhund Reason: 1
Hi.
I'm new to arduino, and all sort of coding.
these is my display: http://www.ebay.com/itm/IIC-I2C-0-96-128X64-White-OLED-Display-Module-AVR-PIC-Arduino-Compatible-/170842973484?pt=LH_DefaultDomain_0&hash=item27c708e52c
And i want my display to show the analogRead (A6) or other variable.

here is my code:


void setup()
{
 Wire.begin();
 
 Serial.begin(9600);
 pinMode(A4, OUTPUT);
 pinMode(A5, INPUT);
 Reset();
}
void loop()
{

 const char* a1 =analogRead(A6);


 digitalWrite(13,HIGH);
 digitalWrite(A4,HIGH);
 delay(30);
 Display8x16Str(0,0, a1);
 Display8x16Str(2,20, "TEST");
 Display8x16Str(4,0, "Wellcom to use");
 Display8x16Str(6,0, "Gem.Arduino");
 digitalWrite(A4,LOW);
 delay(200);

 Reset();

}
}

and here is the error: "TEST_DISPLAY_POTMETER:178: error: invalid conversion from 'int' to 'const char*'"

I tested it without the a1, and used "test" instead, and then it works well.

Do someone have any idea what i can write?



johnwasser

Where is "Display8x16Str()" defined?  Is there a similar function for display an integer?
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

bjhund

#2
Sep 28, 2012, 12:54 am Last Edit: Sep 28, 2012, 01:42 pm by bjhund Reason: 1
Here is the whole code, sorry.

but instead of "TEST1" i would like to put analogRead(A6), bet then its creating the error i wrote above.
Code: [Select]


// Wire Master Writer
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Writes data to an I2C/TWI slave device
// Refer to the "Wire Slave Receiver" example for use with this

// Created 29 March 2006

// This example code is in the public domain.

#include <Wire.h>

#define OLED_ADDRESS    0x51

#define WRITE_CMD       0x01
#define WRITE_DAT       0x02
#define RESET           0x03

#define DISP_8X16STR    0x10
#define DISP_AREA       0x11
#define FILL_AREA       0x12
#define SET_SCROHOR     0x13
#define SET_SCROVER     0x14
#define SET_SCROVERHOR  0x15

#define SET_ADDRESS     0x21

#define PAGE0           0x00
#define PAGE1           0x01
#define PAGE2           0x02
#define PAGE3           0x03
#define PAGE4           0x04
#define PAGE5           0x05
#define PAGE6           0x06
#define PAGE7           0x07

#define SCROLL_UP       0x01
#define SCROLL_DOWN     0x00
#define SCROLL_RIGHT    0x26
#define SCROLL_LEFT     0x27
#define SCROLL_VR       0x29
#define SCROLL_VL       0x2A

#define FRAMS_2         0x07
#define FRAMS_3         0x04
#define FRAMS_4         0x05
#define FRAMS_5         0x00
#define FRAMS_25        0x06
#define FRAMS_64        0x01
#define FRAMS_128       0x02
#define FRAMS_256       0x03

void Display8x16Str(uint8_t page, uint8_t column, const char *str)
{
   Wire.beginTransmission(OLED_ADDRESS);
   Wire.write(DISP_8X16STR);
   Wire.write(page);
   Wire.write(column);
   
   while(*str != '\0')
   {
        Wire.write(*str++);
   }
   Wire.endTransmission();
}
void FillArea(uint8_t spage, uint8_t epage,uint8_t scolumn, uint8_t ecolumn,uint8_t filldata)
{
   Wire.beginTransmission(OLED_ADDRESS);
   Wire.write(FILL_AREA);
   Wire.write(spage);
   Wire.write(epage);
   Wire.write(scolumn);
   Wire.write(ecolumn);
   Wire.write(filldata);
   Wire.endTransmission();
}
void ScrollingHorizontal(uint8_t lr, uint8_t spage, uint8_t epage,uint8_t frames)
{
   Wire.beginTransmission(OLED_ADDRESS);
   Wire.write(SET_SCROHOR);
   Wire.write(lr);
   Wire.write(spage);
   Wire.write(epage);
   Wire.write(frames);
   Wire.endTransmission();
}
void ScrollingVertical(uint8_t scrollupdown, uint8_t rowsfixed, uint8_t rowsscroll, uint8_t scrollstep, uint8_t stepdelay)
{
   Wire.beginTransmission(OLED_ADDRESS);
   Wire.write(SET_SCROVER);
   Wire.write(scrollupdown);
   Wire.write(rowsfixed);
   Wire.write(rowsscroll);
   Wire.write(scrollstep);
   Wire.write(stepdelay);
   Wire.endTransmission();
}
void ScrollingVertivalHorizontal(uint8_t fixedarea, uint8_t scrollarea, uint8_t vlr, uint8_t spage, uint8_t epage, uint8_t frames, uint8_t offset)
{
   Wire.beginTransmission(OLED_ADDRESS);
   Wire.write(SET_SCROVERHOR);
   Wire.write(fixedarea);
   Wire.write(scrollarea);
   Wire.write(vlr);
   Wire.write(spage);
   Wire.write(epage);
   Wire.write(frames);
   Wire.write(offset);
   Wire.endTransmission();
}
void DeactivateScroll()
{
   Wire.beginTransmission(OLED_ADDRESS);
   Wire.write(WRITE_CMD);
   Wire.write(0x2E);
   Wire.endTransmission();
}
void WriteCommand(const char *cmd)
{
   Wire.beginTransmission(OLED_ADDRESS);
   Wire.write(WRITE_CMD);    
   while(*cmd != '\0')
   {
        Wire.write(*cmd++);
   }
   Wire.endTransmission();
}
void WriteData()
{
   unsigned int i;
   Wire.beginTransmission(OLED_ADDRESS);
   Wire.write(WRITE_DAT);    
   for (i=0; i<20; i++)
   {
       // Wire.send(0xF0);  
   }
   for (i=0; i<20; i++)
   {
       // Wire.send(0x0F);  
   }
   for (i=0; i<32; i++)
   {
        Wire.write(0xFF);  
   }
   Wire.endTransmission();
}
void SetAddress(uint8_t page, uint8_t column)
{
   Wire.beginTransmission(OLED_ADDRESS);
   Wire.write(SET_ADDRESS);    
   Wire.write(page);
   Wire.write(column);
   Wire.endTransmission();
}
void Reset()
{
   Wire.beginTransmission(OLED_ADDRESS);
   Wire.write(RESET);    
   Wire.endTransmission();
}
void setup()
{
 Wire.begin();
 Serial.begin(9600);
 pinMode(A4, OUTPUT);
 pinMode(A5, INPUT);
 Reset();
}
void loop()
{
 digitalWrite(A4,HIGH);
 delay(30);
 Display8x16Str(0,0, "TEST1:");
 Display8x16Str(2,20, "TEST2");
 Display8x16Str(4,0, "Wellcom to use");
 Display8x16Str(6,0, "Gem.Arduino");
 digitalWrite(A4,LOW);
delay (200);
 Reset();
}

guix

#3
Sep 28, 2012, 02:30 am Last Edit: Sep 28, 2012, 03:15 am by guix Reason: 1
Hello and welcome :)

In your code, a1 is an integer variable (a number), because analogRead() return an integer. But the function Display8x16Str expect a string variable. So you must convert the integer into a string, maybe this will help: http://www.arduino.cc/playground/Code/PrintingNumbers and also have a look at this: http://arduino.cc/en/Reference/StringConstructor . Good luck :)

liudr

Use the code tag next time you post code (see the red box?):


bjhund

Thank you for answers  :)
have a lot to do to really find out how arduino works :P

trying to find some library that will coop with my problem, just to make it look nicer, and cleaner :)

Go Up