# I2C to a TwiLeDisp4x7s+2L 4 x 7segment DIsplay

I have just bought this from ebay but cant understand how i formulate an I2C instruction to it.

and the data sheet for it is here http://bringyourself.in/wp-content/uploads/2010/04/TwiLeDisp4x7s+2L_-_data_format_1-4.pdf

Any help would be apreciated.

RIchard

I have just received the following instructions from the vendor about how to get this working on I2C but he said it is not in Arduino code but this works on his system.

``````void TwiLeDispIntAndPts(uint8_t address, uint8_t upLed, uint8_t loLed, uint8_t bright_rb, uint8_t bright_7s, int16_t number, uint8_t points)
{
uint8_t i;
uint8_t Buffer[8];
Buffer[0] = ((1 & upLed) << 7) | ((1 & loLed) << 6) | (1 << 5) | (bright_7s & 31);
Buffer[1] = bright_rb & 127;
snprintf(&Buffer[2], 6, "%-4.3f", number);
Buffer[6] = 0b1111 & points;
Buffer[7] = address << 1;
for (i = 0; i <= 6; i++) Buffer[7] ^= Buffer[i];
Wire.beginTransmission(address);
// try this if above will not work: Wire.beginTransmission(address << 1);
Wire.send(&(Buffer[0]), 8);
Wire.endTransmission();
}

// ... put this somewhere in main:

TwiLeDispIntAndPts(3, 0, 1, 5, 31, -567, 0x0F); // it should light lower LED and display "-.5.6.7."
``````

I have tried moving it into a sketch but no combination verifies and i am stuck.

Any help

RIchard

I have tried moving it into a sketch but no combination verifies and i am stuck.

What sketch? Where did you put the function and the function call? What errors did you encounter?

I spent about 2 hours last night moving commands around my sketch program to try to get it talking but to no avail. It just sits there with power proudly isplaying a big red 3 which is it’s I2C address.

I have just been advised that the driver chip is an ATTiny2313 with a bespoke program to run the display.

If i can read the program it will hopefully let me know what commands the 2313 is expecting me to send it - assuming i can understand the program.

The code you posted in Reply #1 should compile and link on the Arduino. If the vendor says it works, it should work.

If it is a compilation issue, then post some code here.

If the code compiles but does nothing, it might be a software issue (function call in wrong place) or a hardware issue.

We can't tell without seeing some code. A picture of the wiring to the Arduino would be nice, too.

Hi, i will post some code tonight but the vendor did say that it has not been used with Arduino before ant his was the code he used in C language ??

Having no grasp of C and very basic Arduino programming means i am trying blind but am determined not to be beaten as it is an I2C connection and once you have the correct addressing and instructions it will look blindingly simple !

Thanks and i will post more tonight.

I have deleted most of the defined values and just added one set of values and a value that increases with every loop

``````#include <Wire.h>

void setup()
{
Wire.begin();
#declare num -267
}
void loop()
{
Wire.beginTransmission(3); // transmit to device #3
Wire.send (3, 0, 1, 5, 31, -567, 0x0F); // it should light lower LED and display "-.5.6.7."
Wire.endTransmission();    // stop transmitting

num++;
delay(5000);
}
``````

but i get loads of errors which i dont understand.

[color=#000000]sketch_nov24a.cpp:9:3: error: invalid preprocessing directive #declare
sketch_nov24a.cpp: In function ‘void loop()’:
sketch_nov24a:10 error: no matching function for call to TwoWire::send(int, int, int, int, int, int, int)’
C:\Users\User\Documents\Arduino-17[1]\Arduino-0021\libraries\Wire.h:54: note: candidates are: void TwoWire::send(unit8_t)
C:\Users\User\Documents\Arduino-17[1]\Arduino-0021\libraries\Wire.h:55: note: void TwoWire::send(unit8_t*, unit_t)
C:\Users\User\Documents\Arduino-17[1]\Arduino-0021\libraries\Wire.h:56: note: void TwoWire::send(int)C:\Users\User\Documents\Arduino-17[1]\Arduino-0021\libraries\Wire.h:57: note: void TwoWire::send(char*)
sketch_nov24a:13: error: ‘num’ was not declared in this scope

Any help would be apreciated.

RIchard

Just tried again and down to 4 errors :-

``````#include <Wire.h>

void setup()

int num = -267
{
Wire.begin();
}

void loop()

{
Wire.beginTransmission(3); // transmit to device #3
Wire.send(3, 0, 1, 5, 31, num, 0x0F); // it should light lower LED and display "-.5.6.7."
Wire.endTransmission();    // stop transmitting

num++;
delay(5000);
}

now the errors i have are :-

sketch_nov24a.cpp: In function 'void setup()':
sketch_nov24a:5: error: expected ',' or ';' before 'Wire'sketch_nov24a.cpp: In function 'void loop':
sketch_nov25a:13: error: 'num' was not declared in this scope

Thanks

RIchard
``````
``````int num = -267
{
Wire.begin();
}
``````

The int statement needs a semicolon on the end. The rest of the code looks like the body of a function, but there is no function name or type preceding it.

The setup() function doesn't have a body. It looks like the int statement is in the wrong place.

The Wire.send() function call is wrong, too. The send function takes two arguments - a pointer to the data to send, and the length of that data in bytes.

Thanks, looks like i am going to have to read the website tuition again as i dont understand.

Lets see what i can do today.

if i am correct i have to call a function from the body and then lower down set the details of the function.

Richard

I have receiver the enclosed code frmo the vendor of the module but i cant get it to compile.

``````#include <Wire.h>

void setup();

int num = -981;
{
Wire.begin();
}

void TwiLeDispIntAndPts(uint8_t address, uint8_t upLed, uint8_t loLed, uint8_t bright_rb, uint8_t bright_7s, int16_t number, uint8_t points)
{
uint8_t i;
uint8_t Buffer[8];
Buffer[0] = ((1 & upLed) << 7) | ((1 & loLed) << 6) | (1 << 5) | (bright_7s & 31);
Buffer[1] = bright_rb & 127;
//snprintf(&Buffer[2], 5, "%d", number); // if this line will not work, try to replace it with these:
Buffer[2] = 1;
Buffer[3] = 2;
Buffer[4] = 3;
Buffer[5] = 4;
Buffer[6] = 0b1111 & points;
Buffer[7] = address << 1;
for (i = 0; i <= 6; i++) Buffer[7] ^= Buffer[i];
//Wire.beginTransmission(address);
// try this if above will not work:
Wire.beginTransmission(address << 1);
Wire.send(&(Buffer[0]), 8);
Wire.endTransmission();
}

void loop()
{
Wire.beginTransmission(3); // transmit to device #3
Wire.send(3, 0, 1, 5, 31, num, 0b00001111);
Wire.endTransmission();    // stop transmitting

num++;
delay(5000);
}
``````

I now get the following error :-

in the brown bar it says :-
[expected unqualified-id before ‘{’ token

then underneath in the black note ares it says :-
sketch_nov25a.cpp: 5: error: expected unqualified-id before ‘{’ token
sketch_nov25a.cpp: In function ‘void loop()’:
sketch-nov25a:33: error: no matching function for call to ‘TwoWire::send(int, int, int, int, int, int, int&, int)’
C:Program files\Arduino\arduino-0021\arduino-0021\libraries\Wire/Wire/Wire.h:54: note candidates are: void TwoWire::send(unit8_t)
C:Program files\Arduino\arduino-0021\arduino-0021\libraries\Wire/Wire/Wire.h:55: note void TwoWire::send(unit8_t*, unit8_t)
C:Program files\Arduino\arduino-0021\arduino-0021\libraries\Wire/Wire/Wire.h:56: note void TwoWire::send(int)
C:Program files\Arduino\arduino-0021\arduino-0021\libraries\Wire/Wire/Wire.h:57: note void TwoWire::send(char*)

Does any one know what is wrong.

I understand the main parts of the code need to remain as they are as there is a program on the attiny2313 that takes the code in the order given so that the LED display shown the value that we have called ‘num’

from this point on i am stuck so any help will be graefully received - my only final thought is that the code we need to run the ATTiny2313 is not compatable with the Arduino ???

thank you

The vendor gave me a correction and i also noticed an error where i had but a value ‘num’ in the string thinking it would show that number on the display but it was stopping it running, replacing it with a random number gets the display working.

``````#include <Wire.h>

void setup()
{
int num = -981;
Wire.begin();
}

void TwiLeDispIntAndPts(uint8_t address, uint8_t upLed, uint8_t loLed, uint8_t bright_rb, uint8_t bright_7s, int16_t number, uint8_t points)
{
uint8_t i;
uint8_t Buffer[8];
Buffer[0] = ((1 & upLed) << 7) | ((1 & loLed) << 6) | (1 << 5) | (bright_7s & 31);
Buffer[1] = bright_rb & 127;
//snprintf(&Buffer[2], 5, "%d", number); // if this line will not work, try to replace it with these:
Buffer[2] = 4;
Buffer[3] = 5;
Buffer[4] = 6;
Buffer[5] = 8;
Buffer[6] = 0b1111 & points;
Buffer[7] = address << 1;
for (i = 0; i <= 6; i++) Buffer[7] ^= Buffer[i];
Wire.beginTransmission(address);
// try this if above will not work: Wire.beginTransmission(address << 1);
Wire.send(&(Buffer[0]), 8);
Wire.endTransmission();
}

void loop()
{
TwiLeDispIntAndPts(3, 0, 1, 5, 31, 1, 0b00001111);
// num++;
delay(1000);
}
``````

the value shown n buffer 2,3,4&5 are what are displayed on the 4 x 7 segment display.

Yippee now to play with it a little.

Dear Arduino forum readers,

I am the man who makes these displays. It is of my own design, programming and assembly. I am not familiar with Arduino, but as it uses C language, I think my given example should work.

billericayboy, does this line with snprintf gives compile error? If not - use it as I gave you and put "num" in loop(), like this: TwiLeDispIntAndPts(3, 0, 1, 5, 31, num, 0); or so..

I know, this codes may be polished to be more optimal. If someone will make better code for my display - write me and I will be able to put it in my web-site (and e-shop) for other Arduino users, for other TwiLeDisp customers.

``````void setup()
{
[glow]  int num = -981;
[/glow]  Wire.begin();
}
``````

num is a local variable that goes out of scope as soon as setup ends. Since it is never referenced anywhere else in setup, what is it's purpose.

Hi PaulS, in short it's purpose was me trying to be too clever !!!

What i was looking at doing was adding a data field that eventually would be provided by an input do i tried to set a variable at the start so the display would display the number shown then in the loop the following code was to display the number and add 1 per 5 second loop.

``````{
Wire.beginTransmission(3); // transmit to device #3
Wire.send(3, 0, 1, 5, 31, num, 0b00001111);
Wire.endTransmission();    // stop transmitting

num++;
delay(5000);
}
``````

All i got were errors saying that num wasa not defined so i changed it to -981 and put a // in front of the num++ command and it worked but did not display the -981. BAck to looking at the code - i realised that the display reads Buffer[2], [3], [4] & [5] as the values it displays.

The num variable was my way of trying to be cleaver and i got it wrong, deleting it made the sketch run as i had it in the wrong place to do what i wanted in any case.

So, if you want to display incrementing values, you need to change what is in Buffer[2] - Buffer[5];

This is easy to do.

``````int num = 134;
for (int j=0; j<100; j++)
{
num++;

sprintf(Buffer, "%6d", num);
Buffer[0] = ((1 & upLed) << 7) | ((1 & loLed) << 6) | (1 << 5) | bright_7s & 31);
Buffer[1] = bright_rb & 127;

Buffer[6] = 0b1111 & points;
Buffer[7] = address << 1;
for (i = 0; i <= 6; i++) Buffer[7] ^= Buffer[i];
Wire.beginTransmission(address);
Wire.send(&(Buffer[0]), 8);
Wire.endTransmission();
}
}
``````

I have written sample code for this unit. Picaxe and Arduino.

http://www.phanderson.com/picaxe/twidisp.html

The developer in Lithuania has these at http://bringyourself.in/

He also has them listed on eBay.

My opinion is that this is a nicely designed and functional unit.

Peter Anderson, www.phanderson.com