Show Posts
Pages: 1 ... 62 63 [64] 65 66 ... 110
946  Using Arduino / Displays / Re: Nokia LCD display shield question on: October 11, 2012, 06:40:13 pm
I have simplified one of the functions from my my MP3 Player. This basically displays data from a string which you supply, scrolling it around by 1 character each time the function is called.
//Scroll through songInfo, shifting 1 characters each time
void printScroll(char* songInfo, byte infoLength, boolean start = false);
void printScroll(char* songInfo, byte infoLength, boolean start){
  static unsigned int tagPosition = 0;
    tagPosition = 0;
  char stringRecover[23] = {0};
  strncpy(stringRecover,&songInfo[tagPosition], 22); //22 character substring starting at [tagPosition]
  tagPosition += 1;
  if (tagPosition >= infoLength - 21){ //subtracting 21 as the last 21 characters are the same as the first.
    tagPosition = 0;

The function does not check the length of the string you supply (I took too much time for my particular project), so you need to ensure that the string is at least 43 characters long, and that the last 21 characters are the same as the first. For example:

"Hello, this string is more than 22 characters longHello, this string is"; //Noting that the last 21 characters are the same as the first.
"Hello,                    Hello,                   "; //This string is padded with spaces to ensure that it is the correct length.

You could use something like this function to automatically format the string and scroll it:
  //This code calls the scroll funtion
  char string[] = "Hello, this is the string I wan't to scroll around the screen";
  scrollString(string, 50); //scroll the string 50 places to the right (will loop around as necessary).


void scrollString(char* suppliedString, byte n){ //Formats then scrolls the string around the screen n times.
  int length = strlen(suppliedString);

  char string[length < 22? 44: length + 22];  //create a longer buffer of minimum size 44 characters (22 + 21 + null).

  strcpy(string, suppliedString); //Copy the supplied string into the new buffer

  //check the length of the string:
  if (length < 22){
    //String is too short!
    memset(string + length, ' ', 22 - length); //so pad with spaces up to the required length
    string[22] = 0; //re null terminate (we just overwrote the null with a ' ')
    length = 22; //string is now 22 characters long
  //Now append the first 21 characters to the end to allow wrap around (so the string can scroll around the screen continuously)
  char stringRecover[22] = {0};
  sprintf(string + length,"%s",stringRecover); //Add the first 21 chars onto the end of songInfo to make it easier to loop through later

  length = strlen(string);
  printScroll(string, length, true); //initial print to the screen, reset loop position to the start.

  for (byte i = 0; i < n - 1; i++){
     printScroll(string, length); //shift around the screen n times.

(Just to note, the formatting function hasn't been tested beyond it compiling as I don't have a screen to hand, but I know the printing function works).
947  Using Arduino / Displays / Re: Sparkfun color LCD shield question, possible problem. on: October 11, 2012, 03:24:24 am
If you go to the downloads page (button which says downloads to the top rifght of the repository), they are all seperated into individual zip files, one for each version.
All the old versions are there because that is how they are stored on my computer in the git folder.
948  Using Arduino / Programming Questions / Re: Wire library includes, but error says "Not Defined" on: October 10, 2012, 05:51:55 pm
I believe then it is just a case of changing:

#include <BMP085.h>


#include "BMP085.h"

The two are different. The first implies a system file (somewhere buried deep in the /hardware/tools/avr/avr/ folder), the second a local file, such as arduino libraries and files in your sketch folder.
949  Using Arduino / Programming Questions / Re: Wire library includes, but error says "Not Defined" on: October 10, 2012, 04:56:29 pm
Have you put a semicolon at the end of the class definition in BMP085.h?

(Post your code! Otherwise it is impossible to help beyond chance guesses)
950  Using Arduino / Displays / Re: Sparkfun color LCD shield question, possible problem. on: October 10, 2012, 04:52:07 pm
If you get a blank screen it *usually* means you have the wrong driver. If you tried EPSON in your first attempt and that didn't work, try PHILLIPS_0
(Side note: It looks the same as mine in terms of connector colour, and mine is PHILLIPS, but then you can't really tell which is why my library supports many variants of both phillips and epson).
951  Using Arduino / Microcontrollers / Re: atmega324p bootloader can't write flash on: October 10, 2012, 04:35:45 pm
You have specified to avrdude to program the chip using ISP (note the avrisp), and yet you are trying to use a bootloader. The two are very different.

Off the top of my head I can't remeber what ATmegaBOOT uses in relation to avrdude. I think that optiboot is 'arduino' (instead of avrisp), or is it 'stk500v1'. Would have to check.

Try this:
avrdude -c arduino -p m324p -P com1 -b 19200 -D -U flash:w:main_blinking.hex:i
952  Using Arduino / Microcontrollers / Re: My Core + Bootloader Version for ATTiny's on: October 10, 2012, 02:08:19 am
Basically at the expense of 576B of flash you get to upload via serial port in the same way an arduino does. This means fewer pin need to be broken out for programming.
Another advantage is that my bootloader version tunes the internal oscillator which makes serial comma more reliable.
953  Using Arduino / Microcontrollers / My Core + Bootloader Version for ATTiny's on: October 09, 2012, 06:02:40 pm
Just for those who are interested, I have finally got around to uploading my version of the 'tiny' core for Arduino. Along with that I have included my version of Optiboot which works with the ATtiny84 and ATtiny85 processors (The optiboot version includes TinyTuner built in to calibrate the oscillator allowing a Software UART to be reliable).

The Core is hosted on github @:

Beta testers are very welcome as there are probably a few bugs in it which need ironing out (with the exception of the bootloader which is fully tested and functional).

I have also uploaded the fix for the PCREL error to the repository so it is easy to find.
954  Using Arduino / Programming Questions / Re: Combining Serial prints ... HELP! on: October 09, 2012, 03:49:32 pm
Just for the sake of interest, the method using multiple print() calls is faster than the sprintf() method (in one simple test).

For a loop of 100 calls to printing the data for each, the results are:
multiple print()'s : 210556 us
sprintf() : 210972 us

That is at 115200 baud and the same group of calls as in that snippet of code you posted.

For a loop of 10000 calls to printing the data for each, the results are:
multiple print()'s : 23378412 us
sprintf() : 22798020 us

Interesting, sprintf() seems to have recovered. I think the first test may have been biased as for the first few iterations sprintf() had more to print as micros() had a larger value (more decimal digits)

But yeah as has been pointed out:
115,200 baud = 11520 bytes per second = 11.52 bytes per millisecond, not including the time it takes to get the data and load it into the buffer etc.
955  Using Arduino / Programming Questions / Re: Combining Serial prints ... HELP! on: October 09, 2012, 02:35:17 pm
char buffer[100]; //This is where the data will be merged into. Ideally you should make this as small as you can whilst still having enough room
sprintf(buffer,"1 %ul %d %d %d %d %d", millis(), distance, pressure, prSwitch, Fldtemp); //merge together
Serial.println(buffer); //send

Basically sprintf has a set of special characters (the %_ where the _ is a letter(s)). As it works along it replaces each of these with the corresponding variable (first % is the first variable, second % is the second variable and so on).

Each of the special charaters formats the variable in a different way. For example %d takes an integer and converts it to a string of numbers. %c takes a byte and prints the corresponding ascii character (so 30 would print ' ' (space)). %ul takes an unsigned long type (which is why it is used for millis()).
There are others as well, you would have to look on the cplusplus reference (if you google sprintf() you should find it).

Note that in my example as I don't know the variable types of your numbers I have assumed that they are all bytes or integers (so %d) except for millis() which I know returns an unsigned long.
956  Using Arduino / Displays / Re: Nokia LCD display shield question on: October 08, 2012, 09:17:41 am
Yep. there is no funtion buoy in to do that so you will have to do it manually. I have some code from a previous project which I can find for you if you would like.
957  Using Arduino / Displays / Re: Nokia LCD display shield question on: October 08, 2012, 07:50:09 am
If you go through that function and find stuff like this:
if (cts = true){
 //always called as assignment returns true

if (cts = false){
 //neve called as assignment returns true
It is wrong. It should be like this:
if (cts == true){
 //called when cts is true

if (cts == false){
 //called when cts is false

Can you see the difference?

Your code is using an assignment (set cts to equal true) which regardless of the math you do always returns true.
The second code block is using an equality operator - the statement is true if this IS EQUAL to that, else it is false.

For cases where you are checking if something is true or false, you are best using this:
if (cts){
 //called when cts is true

if (!cts){
  //called when cts is NOT true, i.e. false
This is important as when something returns true you can't guarantee that it is == to 0x01 (which is what true is defined as). In the world of C/C++, boolean true is anything which is not 0.
958  Using Arduino / Programming Questions / Re: Code help on: October 07, 2012, 06:24:55 pm
Right, I went back to you first post and worked from what you said was wrong. A couple of corrections later:
#define PIN_SCE   7
#define PIN_RESET 6
#define PIN_DC    5
#define PIN_SDIN  4
#define PIN_SCLK  3
int ledlight = 13;
#define LCD_C     LOW
#define LCD_D     HIGH

#define LCD_X     84
#define LCD_Y     48
#include <PS2Keyboard.h>

const int DataPin = 8;
const int IRQpin =  2;
PS2Keyboard keyboard;
static const byte ASCII[][5] =
 {0x00, 0x00, 0x00, 0x00, 0x00} // 20 
,{0x00, 0x00, 0x5f, 0x00, 0x00} // 21 !
,{0x00, 0x07, 0x00, 0x07, 0x00} // 22 "
,{0x14, 0x7f, 0x14, 0x7f, 0x14} // 23 #
,{0x24, 0x2a, 0x7f, 0x2a, 0x12} // 24 $
,{0x23, 0x13, 0x08, 0x64, 0x62} // 25 %
,{0x36, 0x49, 0x55, 0x22, 0x50} // 26 &
,{0x00, 0x05, 0x03, 0x00, 0x00} // 27 '
,{0x00, 0x1c, 0x22, 0x41, 0x00} // 28 (
,{0x00, 0x41, 0x22, 0x1c, 0x00} // 29 )
,{0x14, 0x08, 0x3e, 0x08, 0x14} // 2a *
,{0x08, 0x08, 0x3e, 0x08, 0x08} // 2b +
,{0x00, 0x50, 0x30, 0x00, 0x00} // 2c ,
,{0x08, 0x08, 0x08, 0x08, 0x08} // 2d -
,{0x00, 0x60, 0x60, 0x00, 0x00} // 2e .
,{0x20, 0x10, 0x08, 0x04, 0x02} // 2f /
,{0x3e, 0x51, 0x49, 0x45, 0x3e} // 30 0
,{0x00, 0x42, 0x7f, 0x40, 0x00} // 31 1
,{0x42, 0x61, 0x51, 0x49, 0x46} // 32 2
,{0x21, 0x41, 0x45, 0x4b, 0x31} // 33 3
,{0x18, 0x14, 0x12, 0x7f, 0x10} // 34 4
,{0x27, 0x45, 0x45, 0x45, 0x39} // 35 5
,{0x3c, 0x4a, 0x49, 0x49, 0x30} // 36 6
,{0x01, 0x71, 0x09, 0x05, 0x03} // 37 7
,{0x36, 0x49, 0x49, 0x49, 0x36} // 38 8
,{0x06, 0x49, 0x49, 0x29, 0x1e} // 39 9
,{0x00, 0x36, 0x36, 0x00, 0x00} // 3a :
,{0x00, 0x56, 0x36, 0x00, 0x00} // 3b ;
,{0x08, 0x14, 0x22, 0x41, 0x00} // 3c <
,{0x14, 0x14, 0x14, 0x14, 0x14} // 3d =
,{0x00, 0x41, 0x22, 0x14, 0x08} // 3e >
,{0x02, 0x01, 0x51, 0x09, 0x06} // 3f ?
,{0x32, 0x49, 0x79, 0x41, 0x3e} // 40 @
,{0x7e, 0x11, 0x11, 0x11, 0x7e} // 41 A
,{0x7f, 0x49, 0x49, 0x49, 0x36} // 42 B
,{0x3e, 0x41, 0x41, 0x41, 0x22} // 43 C
,{0x7f, 0x41, 0x41, 0x22, 0x1c} // 44 D
,{0x7f, 0x49, 0x49, 0x49, 0x41} // 45 E
,{0x7f, 0x09, 0x09, 0x09, 0x01} // 46 F
,{0x3e, 0x41, 0x49, 0x49, 0x7a} // 47 G
,{0x7f, 0x08, 0x08, 0x08, 0x7f} // 48 H
,{0x00, 0x41, 0x7f, 0x41, 0x00} // 49 I
,{0x20, 0x40, 0x41, 0x3f, 0x01} // 4a J
,{0x7f, 0x08, 0x14, 0x22, 0x41} // 4b K
,{0x7f, 0x40, 0x40, 0x40, 0x40} // 4c L
,{0x7f, 0x02, 0x0c, 0x02, 0x7f} // 4d M
,{0x7f, 0x04, 0x08, 0x10, 0x7f} // 4e N
,{0x3e, 0x41, 0x41, 0x41, 0x3e} // 4f O
,{0x7f, 0x09, 0x09, 0x09, 0x06} // 50 P
,{0x3e, 0x41, 0x51, 0x21, 0x5e} // 51 Q
,{0x7f, 0x09, 0x19, 0x29, 0x46} // 52 R
,{0x46, 0x49, 0x49, 0x49, 0x31} // 53 S
,{0x01, 0x01, 0x7f, 0x01, 0x01} // 54 T
,{0x3f, 0x40, 0x40, 0x40, 0x3f} // 55 U
,{0x1f, 0x20, 0x40, 0x20, 0x1f} // 56 V
,{0x3f, 0x40, 0x38, 0x40, 0x3f} // 57 W
,{0x63, 0x14, 0x08, 0x14, 0x63} // 58 X
,{0x07, 0x08, 0x70, 0x08, 0x07} // 59 Y
,{0x61, 0x51, 0x49, 0x45, 0x43} // 5a Z
,{0x00, 0x7f, 0x41, 0x41, 0x00} // 5b [
,{0x02, 0x04, 0x08, 0x10, 0x20} // 5c ¥
,{0x00, 0x41, 0x41, 0x7f, 0x00} // 5d ]
,{0x04, 0x02, 0x01, 0x02, 0x04} // 5e ^
,{0x40, 0x40, 0x40, 0x40, 0x40} // 5f _
,{0x00, 0x01, 0x02, 0x04, 0x00} // 60 `
,{0x20, 0x54, 0x54, 0x54, 0x78} // 61 a
,{0x7f, 0x48, 0x44, 0x44, 0x38} // 62 b
,{0x38, 0x44, 0x44, 0x44, 0x20} // 63 c
,{0x38, 0x44, 0x44, 0x48, 0x7f} // 64 d
,{0x38, 0x54, 0x54, 0x54, 0x18} // 65 e
,{0x08, 0x7e, 0x09, 0x01, 0x02} // 66 f
,{0x0c, 0x52, 0x52, 0x52, 0x3e} // 67 g
,{0x7f, 0x08, 0x04, 0x04, 0x78} // 68 h
,{0x00, 0x44, 0x7d, 0x40, 0x00} // 69 i
,{0x20, 0x40, 0x44, 0x3d, 0x00} // 6a j
,{0x7f, 0x10, 0x28, 0x44, 0x00} // 6b k
,{0x00, 0x41, 0x7f, 0x40, 0x00} // 6c l
,{0x7c, 0x04, 0x18, 0x04, 0x78} // 6d m
,{0x7c, 0x08, 0x04, 0x04, 0x78} // 6e n
,{0x38, 0x44, 0x44, 0x44, 0x38} // 6f o
,{0x7c, 0x14, 0x14, 0x14, 0x08} // 70 p
,{0x08, 0x14, 0x14, 0x18, 0x7c} // 71 q
,{0x7c, 0x08, 0x04, 0x04, 0x08} // 72 r
,{0x48, 0x54, 0x54, 0x54, 0x20} // 73 s
,{0x04, 0x3f, 0x44, 0x40, 0x20} // 74 t
,{0x3c, 0x40, 0x40, 0x20, 0x7c} // 75 u
,{0x1c, 0x20, 0x40, 0x20, 0x1c} // 76 v
,{0x3c, 0x40, 0x30, 0x40, 0x3c} // 77 w
,{0x44, 0x28, 0x10, 0x28, 0x44} // 78 x
,{0x0c, 0x50, 0x50, 0x50, 0x3c} // 79 y
,{0x44, 0x64, 0x54, 0x4c, 0x44} // 7a z
,{0x00, 0x08, 0x36, 0x41, 0x00} // 7b {
,{0x00, 0x00, 0x7f, 0x00, 0x00} // 7c |
,{0x00, 0x41, 0x36, 0x08, 0x00} // 7d }
,{0x10, 0x08, 0x08, 0x10, 0x08} // 7e ←
,{0x78, 0x46, 0x41, 0x46, 0x78} // 7f →

void LcdCharacter(char character)
  LcdWrite(LCD_D, 0x00);
  for (int index = 0; index < 5; index++)
    LcdWrite(LCD_D, ASCII[character - 0x20][index]);
  LcdWrite(LCD_D, 0x00);

void LcdClear(void)
  for (int index = 0; index < LCD_X * LCD_Y / 8; index++)
    LcdWrite(LCD_D, 0x00);

void LcdInitialise(void)
  pinMode(PIN_SCE, OUTPUT);
  pinMode(PIN_DC, OUTPUT);
  pinMode(PIN_SDIN, OUTPUT);
  pinMode(PIN_SCLK, OUTPUT);
  digitalWrite(PIN_RESET, LOW);
  digitalWrite(PIN_RESET, HIGH);
  LcdWrite(LCD_C, 0x21 );  // LCD Extended Commands.
  LcdWrite(LCD_C, 0xB1 );  // Set LCD Vop (Contrast).
  LcdWrite(LCD_C, 0x04 );  // Set Temp coefficent. //0x04
  LcdWrite(LCD_C, 0x14 );  // LCD bias mode 1:48. //0x13
  LcdWrite(LCD_C, 0x0C );  // LCD in normal mode.
  LcdWrite(LCD_C, 0x20 );
  LcdWrite(LCD_C, 0x0C );

void LcdString(const char characters[])

void LcdString(char* characters){
  while (*characters)

void LcdWrite(byte dc, byte data)
  digitalWrite(PIN_DC, dc);
  digitalWrite(PIN_SCE, LOW);
  shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data);
  digitalWrite(PIN_SCE, HIGH);

void setup(void)
{ delay(1000);
   keyboard.begin(DataPin, IRQpin);
  LcdString("Hello World!");

void loop(void)
  if (keyboard.available()) {
    // read the next key
    char c =;
    // check for some of the special keys
    if (c == PS2_ENTER) {
    } else if (c == PS2_TAB) {
    } else if (c == PS2_ESC) {
    } else if (c == PS2_PAGEDOWN) {
    } else if (c == PS2_PAGEUP) {
    } else if (c == PS2_LEFTARROW) {
    } else if (c == PS2_RIGHTARROW) {
    } else if (c == PS2_UPARROW) {
    } else if (c == PS2_DOWNARROW) {
    } else if (c == PS2_DELETE) {
    } else {
      // otherwise, just print all normal characters

First as pointed out, this:
int ledlight = 13
Should be this:
int ledlight = 13;

Secondly this:
Should be this:

Finally, you cant use this:
void LcdString(char* characters){
  while (*characters)
with constant string literals. You have to have a seperate function to handle them. Fortunately C++ can handle overloaded function calls where you have two functions with the same name, but take different parameters/variables in the call. So lets overload LcdString and add the ability to add constant strings (the clue is in the name: const)
Lets add this:
void LcdString(const char characters[])
Which takes the constant string and type casts it to the non constant version. Of course this can be achieved with a simple type cast as such:
But it makes the code less messy to have a seperate function.
959  Using Arduino / General Electronics / Re: Components designated "SK"? on: October 07, 2012, 02:15:24 pm
Could you post a picture?
960  Using Arduino / Programming Questions / Re: How to enable the External Occillation. on: October 07, 2012, 10:58:16 am
It won't go much beyond 20MHz.

I tried running an atmega1284 at 24MHz (bought the wrong crystal by mistake) and while it ran, anything that tries to use the SRAM for more than a couple of bytes causes it to crash.

If you want a faster processor, get a Due (when it comes out) or an atxmega chip (someone made a core for them i think).
Pages: 1 ... 62 63 [64] 65 66 ... 110