Arduino Robot can't draw bmp-pictures and play music from card

Hi guys! Have a problem with my robot. It's display do not draw BMP and play melodies with the code from Arduino Robot examples. With the help of standart TFT example from IDE I have tested display and discovered that it can read bmp-files from my card and draw images . As we can see the card and display are not broken but Robot examples and libraries for drawing and playing music don't work. I have tested different versions of IDE but it didn't help. What is the problem?

You have to explain a bit more. How is the melody being played? Does the robot play melody when not reading bmp?

mart256:
You have to explain a bit more. How is the melody being played? Does the robot play melody when not reading bmp?

The melodies and bmp-pictures are on sd-card. When you write command in IDE Robot.playFile(filename) robot reads melody from card and play it with dynamic. Command Robot.drawBMP(filename) makes TFT-display to read bmp pictures from sd card (card is in display). Both pictures and music don't working. The code is right because I take it from IDE examples for robot.

And the code?..

mart256:
And the code?..

1st example code:

#include <ArduinoRobot.h> // include the robot library
#include <Wire.h>
#include <SPI.h>

/* Dancing steps:
S: stop
L: turn left
R: turn right
F: go forward
B: go backwards

The number after each command determines how long
each step lasts. Each number is 1/2 second long.

The "\0" indicates end of string
*/
char danceScript[] = "S4L1R1S2F1B1S1\0";

int currentScript = 0; // what step are we at

int currentSong = 0; // keep track of the current song
static const int SONGS_COUNT = 3; // number of songs

// an array to hold the songs
char musics[][11] = {
"melody.sqm",
"menu.sqm",
"chase.sqm",
};

// variables for non-blocking delay
long waitFrom;
long waitTime = 0;

void setup() {
// initialize the Robot, SD card, display, and speaker
Robot.begin();
Robot.beginSpeaker();
Robot.beginSD();
Robot.beginTFT();

// draw "lg0.bmp" and "lg1.bmp" on the screen
Robot.displayLogos();

// Print instructions to the screen
Robot.text("1. Use left and\n right key to switch\n song", 5, 5);
Robot.text("2. Put robot on the\n ground to dance", 5, 33);

// wait for a few soconds
delay(3000);

setInterface(); // display the current song
play(0); //play the first song in the array

resetWait(); //Initialize non-blocking delay
}

void loop() {
// read the butttons on the robot
int key = Robot.keyboardRead();

// Right/left buttons play next/previous song
switch (key) {
case BUTTON_UP:
case BUTTON_LEFT:
play(-1); //play previous song
break;
case BUTTON_DOWN:
case BUTTON_RIGHT:
play(1); //play next song
break;
}

// dance!
runScript();
}

// Dancing function
void runScript() {
if (!waiting()) { // if the previous instructions have finished
// get the next 2 commands (direction and duration)
parseCommand(danceScript[currentScript], danceScript[currentScript + 1]);
currentScript += 2;
if (danceScript[currentScript] == '\0') // at the end of the array
currentScript = 0; // start again at the beginning
}
}

// instead of delay, use this timer
boolean waiting() {
if (millis() - waitFrom >= waitTime)
return false;
else
return true;
}

// how long to wait
void wait(long t) {
resetWait();
waitTime = t;
}

// reset the timer
void resetWait() {
waitFrom = millis();
}

// read the direction and dirstion of the steps
void parseCommand(char dir, char duration) {
//convert the scripts to action
switch (dir) {
case 'L':
Robot.motorsWrite(-255, 255);
break;
case 'R':
Robot.motorsWrite(255, -255);
break;
case 'F':
Robot.motorsWrite(255, 255);
break;
case 'B':
Robot.motorsWrite(-255, -255);
break;
case 'S':
Robot.motorsStop();
break;
}
//You can change "500" to change the pace of dancing
wait(500 * (duration - '0'));
}

// display the song
void setInterface() {
Robot.clearScreen();
Robot.stroke(0, 0, 0);
Robot.text(musics[0], 0, 0);
}

// display the next song
void select(int seq, boolean onOff) {
if (onOff) { //select
Robot.stroke(0, 0, 0);
Robot.text(musics[seq], 0, 0);
} else { //deselect
Robot.stroke(255, 255, 255);
Robot.text(musics[seq], 0, 0);
}
}

// play the slected song
void play(int seq) {
select(currentSong, false);
if (currentSong <= 0 && seq == -1) { //previous of 1st song?
currentSong = SONGS_COUNT - 1; //go to last song
} else if (currentSong >= SONGS_COUNT - 1 && seq == 1) { //next of last?
currentSong = 0; //go to 1st song
} else {
currentSong += seq; //next song
}
Robot.stopPlayFile();
Robot.playFile(musics[currentSong]);
select(currentSong, true); //display the current song
}

2d example code:
#include <ArduinoRobot.h> // include the robot library
#include <Wire.h>
#include <SPI.h>

const int NUM_PICS = 4; //Total number of pictures in Gallery

// name the modes
const int CONTROL_MODE_KEY = 0;
const int CONTROL_MODE_COMPASS = 1;

char buffer[] = "pic1.bmp"; // current file name
int i = 1; // Current gallery sequence counter
int mode = 0; // Current mode

// text to display on screen
char modeNames[][9] = { "keyboard", "tilt " };

void setup() {
// initialize the Robot, SD card, display, and speaker
Robot.beginSD();
Robot.beginTFT();
Robot.begin();

// draw "lg0.bmp" and "lg1.bmp" on the screen
Robot.displayLogos();

// draw init3.bmp from the SD card on the screen
Robot.drawBMP("init3.bmp", 0, 0);

// display instructions
Robot.stroke(0, 0, 0);
Robot.text("The gallery\n\n has 2 modes, in\n keyboard mode, L/R\n key for switching\n pictures, U/D key\n for changing modes", 5, 5);
delay(6000);
Robot.clearScreen();
Robot.drawBMP("pb.bmp", 0, 0);
Robot.text("In tilt mode,\n quickly tilt the\n robot to switch\n pictures", 5, 5);
delay(4000);
}

void loop() {
buffer[3] = '0' + i; // change filename of the img to be displayed
Robot.drawBMP(buffer, 0, 0); // draw the file on the screen
// change control modes
switch (mode) {
case CONTROL_MODE_COMPASS:
compassControl(3);
break;
case CONTROL_MODE_KEY:
keyboardControl();
break;
}
delay(200);
}

void keyboardControl() {
//Use buttons to control the gallery
while (true) {
int keyPressed = Robot.keyboardRead(); // read the button values
switch (keyPressed) {
case BUTTON_LEFT: // display previous picture
if (--i < 1) i = NUM_PICS;
return;
case BUTTON_MIDDLE: // do nothing
case BUTTON_RIGHT: // display next picture
if (++i > NUM_PICS) i = 1;
return;
case BUTTON_UP: // change mode
changeMode(-1);
return;
case BUTTON_DOWN: // change mode
changeMode(1);
return;
}
}
}

// if controlling by the compass
void compassControl(int change) {
// Rotate the robot to change the pictures
while (true) {
// read the value of the compass
int oldV = Robot.compassRead();

//get the change of angle
int diff = Robot.compassRead() - oldV;
if (diff > 180) diff -= 360;
else if (diff < -180) diff += 360;

if (abs(diff) > change) {
if (++i > NUM_PICS) i = 1;
return;
}

// chage modes, if buttons are pressed
int keyPressed = Robot.keyboardRead();
switch (keyPressed) {
case BUTTON_UP:
changeMode(-1);
return;
case BUTTON_DOWN:
changeMode(1);
return;
}
delay(10);
}
}

// Change the control mode and display it on the LCD
void changeMode(int changeDir) {
// alternate modes
mode += changeDir;
if (mode < 0) {
mode = 1;
} else if (mode > 1)
mode = 0;

// display the mode on screen
Robot.fill(255, 255, 255);
Robot.stroke(255, 255, 255);
Robot.rect(0, 0, 128, 12);
Robot.stroke(0, 0, 0);
Robot.text("Control:", 2, 2);
Robot.text(modeNames[mode], 52, 2);
delay(1000);
}