Problem with converting this single line in a library example to Arduino 1.0

Hello, I downloaded and installed a SparkFun library for controlling this camera: https://www.sparkfun.com/products/10061
but when I verified the code I got this error report:

As of Arduino 1.0, the 'BYTE' keyword is no longer supported.
Please use Serial.write() instead.

on the line of code that looks like this(line 73):

MemoryCard.file.print(response[i], BYTE);

So I tried this:

MemoryCard.file.write(response[i]);

but, that didn't work either as I got this error report:

error: overriding 'virtual size_t Print::write(uint8_t)'

So my question is how do I fix that line to make it Arduino 1.0 compatible?

Please post a complete sketch (preferably a minimal one) that demonstrates the problem. We currently have no way to know what the type of response [ i ] is.

I, too, am having the same issue. Here is the code I am working with (down below, copied from elsewhere), but have had the same problem in code from other sources trying to do the same thing basically - take a pic with the linkSprite jpeg camera and write it to an sd card on the sparkfun sd shield.

the trouble line, as described by ebird:

MemoryCard.file.print(response[i], BYTE);

with the following change, i was at least able to upload/compile successfully, but then there is an issue with a couple other files in libraries:

MemoryCard.file.print(Serial.write(response[i]));

but this gives the following errors:
/Applications/Arduino 2.app/Contents/Resources/Java/libraries/MemoryCard/MemoryCardDevice.cpp: In function 'boolean callback_makeDirPath(SdFile&, char*, boolean, void*)':
/Applications/Arduino 2.app/Contents/Resources/Java/libraries/MemoryCard/MemoryCardDevice.cpp:129: error: no matching function for call to 'SdFile::makeDir(SdFile&, char*&)'
/Applications/Arduino 2.app/Contents/Resources/Java/libraries/SdFat/SdBaseFile.h:275: note: candidates are: bool SdBaseFile::makeDir(SdBaseFile*, const char*)

Again, I am running Arduino 2.0 on a Mac, using Uno and the SD shield from Sparkfun. Any help would be greatly appreciated!

Complete code:

/*
JPEG Camera Example Sketch
The sketch will take a picture on the JPEG Serial Camera and store the jpeg to an SD card
on an SD Shield
Written by Ryan Owens
SparkFun Electronics

Hardware Notes:
This sketch assumes the arduino has the microSD shield from SparkFun attached.
The camera Rx/Tx should be attached to pins 2 and 3.
IMPORTANT: The JPEG camera requires a TTL level shifter between the camera output
and the arduino. Bypassing this may damage the Arduino pins.
*/

//This example requires the MemoryCard, SdFat, JPEGCamera and NewSoftSerial libraries
#include <MemoryCard.h>
#include <SdFat.h>
#include <JPEGCamera.h>
#include <SoftwareSerial.h>

//Create an instance of the camera
JPEGCamera camera;

//Create a character array to store the cameras response to commands
char response[32];
//Count is used to store the number of characters in the response string.
unsigned int count=0;
//Size will be set to the size of the jpeg image.
int size=0;
//This will keep track of the data address being read from the camera
int address=0;
//eof is a flag for the sketch to determine when the end of a file is detected
//while reading the file data from the camera.
int eof=0;

void setup()
{
    //Setup the camera, serial port and memory card
    camera.begin();
    Serial.begin(9600);
    MemoryCard.begin();

    //Reset the camera
    count=camera.reset(response);
    delay(3000);

    //Take a picture
    count=camera.takePicture(response);
    //Print the response to the 'TAKE_PICTURE' command.
    Serial.write(response);
    Serial.write(count);
    Serial.println();

    //Get the size of the picture
    count = camera.getSize(response, &size);
    //Print the size
    Serial.print("Size: ");
    Serial.println(size);

    //Create a file called 'test.txt' on the SD card.
    //NOTE: The memoryCard libary can only create text files.
    //The file has to be renamed to .jpg when copied to a computer.
    MemoryCard.open("/test.txt", true);
    //Starting at address 0, keep reading data until we've read 'size' data.
    while(address < size)
    {
        //Read the data starting at the current address.
        count=camera.readData(response, address);
        //Store all of the data that we read to the SD card
        for(int i=0; i<count; i++){
            //Check the response for the eof indicator (0xFF, 0xD9). If we find it, set the eof flag
            if((response[i] == (char)0xD9) && (response[i-1]==(char)0xFF))eof=1;
            //Save the data to the SD card
            MemoryCard.file.print(response[i], BYTE);
            //If we found the eof character, get out of this loop and stop reading data
            if(eof==1)break;
        }
        //Increment the current address by the number of bytes we read
        address+=count;
        //Make sure we stop reading data if the eof flag is set.
        if(eof==1)break;
    }
    //Close the file
     MemoryCard.close();
     Serial.print("Done.");
}

void loop()
{

}

I haven't looked at the library source, but those error messages seem to indicate that the SDFat library API has changed and the MemoryCard library has not been updated to match it. To figure out the cause and correct the errors you will need to look at the code where the errors are being reported, identify the API being called, and see what method/function within that API the call was intended to correspond to. Then you will presumably need to correct the calling library to make it compatible with the new API.

Well the Serial.print method has been changed in 1.0.x this way:
Serial.print(i,BYTE);
must be replaced by
Serial.write((byte) i);

So it might be the same for your memory card library:
MemoryCard.file.print(response*, BYTE);*
might need to be replaced by
MemoryCard.file.write((byte)response*);*
_*I would also suggest you try my library at:Google Code Archive - Long-term storage for Google Code Project Hosting.
HTH

Thanks for the responses. I understand there are some compatibility issues, however I don't know the exact code to substitute since I am rather new to programming, etc. But I did try a few things to no avail.

manufwi - I did come across your library, but all i could find were download links to .ino files, which gave various errors on their own (e.g., "test_cam4:5: error: 'Serial1' was not declared in this scope"). Could you please provide a bit more instruction on what we need to download and where to place any files? Should these all just work on their own?

Only files I could find for download were:

test_cam_3.ino
test_cam_sserial.ino
test_cam4.ino
take_photo_to_SD.ino

Thanks again!

sorry - actually just realized 'Serial1' is for Leonardo (I am using UNO). still, none of the others work 'as is'. thanks...

Use the sserial one (software serial). Also do not forget to download the library (either using git or by browsing the source files): there are 2 file: one .cpp and one .h to put in arduino-1.0.x/libraries/JPEGCamera/ directory and you're done.

This is great - thanks for sharing - at least now the code uploads with no glitches.

Few more questions though - 1) does pin 10 = TXD out and pin 11 = RXD in in the following line:

SoftwareSerial s(10,11);
  1. Should the sketch 'take_photo_to_SD' also work as-is with the Sparkfun SD shield in place?

  2. I only see 'garble' in the serial feed, might this mean my camera is shot?

Thanks again for your help and patience...

Software pins are RX,TX.
I have no idea for the SD shield compatibility, this sketch is not mine. You should check the SD library page on the arduino website.
The serial feed is a binary file, the raw jpeg file so it looks garbled. Choose a serial terminal application on your PC that can output the raw feed to a file and just open this file with an image viewer!
HTH

Hello,
I'm newbie. I downloaded your files and the complete JPEGCamera Library. When i try to upload this code to my Arduino Mega2560 (while cam is connected to RX2, TX2 i-e Serial2), i got the following error.

test_cam_3:6: error: 'JPEGCamera' does not name a type
test_cam_3.ino: In function 'void loop()':
test_cam_3:24: error: 'cam' was not declared in this scope

And the code looks like:

#include <SoftwareSerial.h>
#include <JPEGCamera.h>

SoftwareSerial sserial(17,16);
JPEGCamera cam(Serial2/*sserial*/);
char resp[10];

I also pasted both the libraries into my sketch folder. Can you please help me where i'm going wrong.?

You mus put the JPEGCamera.h and .cpp file in arduino/libraries/JPEGCamera directory.
HTH

This is the test code to the Arduino camera SEN-10061 2560 R3.
Complete code:
String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
byte feedBackString[4000];
boolean feedBackComplete = false;
boolean endOfPic = false;
unsigned long numOfByte=0;
byte count=0;
byte pic_size1=0;
byte pic_size2=0;

byte flg= 255;
const byte flg_wait= 255;
const byte flg_reset= 0;
const byte flg_size= 1;
const byte flg_baud= 2;
const byte flg_takepic= 3;
const byte flg_readsize= 4;
const byte flg_readjpeg= 5;
const byte flg_stop= 6;
const byte flg_compress=7;
#define setFlag(a) flg=a
//---------------------------------------------------------//
// CAC HAM DIEU KHIEN CAM
//---------------------------------------------------------//
void cmd_reset()
{
flg = flg_reset;
Serial2.write(86); //0x56
Serial2.write(0); //0x00
Serial2.write(38); // 0x26
Serial2.write(0); //0x00
Serial2.flush();
}
void cmd_size1() //160x120
{
flg= flg_size;
Serial2.write(86); //0x56
Serial2.write(0); //0x00
Serial2.write(49); //0x31
Serial2.write(5); //0x05
Serial2.write(4); //0x04
Serial2.write(1); //0x01
Serial2.write(0); //0x00
Serial2.write(25); //0x19
Serial2.write(34); //0x22
Serial2.flush();
}
void cmd_size2() //320xx240
{
flg= flg_size;
Serial2.write(86); //0x56
Serial2.write(0); //0x00
Serial2.write(49); //0x31
Serial2.write(5); //0x05
Serial2.write(4); //0x04
Serial2.write(1); //0x01
Serial2.write(0); //0x00
Serial2.write(25); //0x19
Serial2.write(17); //0x11
Serial2.flush();
}
void cmd_size3() //640x480
{
flg= flg_size;
Serial2.write(86); //0x56
Serial2.write(0); //0x00
Serial2.write(49); //0x31
Serial2.write(5); //0x05
Serial2.write(4); //0x04
Serial2.write(1); //0x01
Serial2.write(0); //0x00
Serial2.write(25); //0x19
Serial2.write(0); //0x00
Serial2.flush();
}
void cmd_baud9600()
{
flg= flg_baud;
Serial2.write(86); //0x56
Serial2.write(0); //0x00
Serial2.write(36); //0x24
Serial2.write(3); //0x03
Serial2.write(1); //0x01
Serial2.write(174); //0xAE
Serial2.write(200); //0xC8
Serial.println("WARNNING: change baudrate to 9600!");
Serial2.begin(9600);
Serial2.flush();
}
void cmd_baud38400()
{
flg= flg_baud;
Serial2.write(86); //0x56
Serial2.write(0); //0x00
Serial2.write(36); //0x24
Serial2.write(3); //0x03
Serial2.write(1); //0x01
Serial2.write(42); //0x2A
Serial2.write(242); //0xF2

Serial.println("WARNNING: change baudrate to 38400!");
Serial2.begin(38400);
Serial2.flush();
}
void cmd_cpr255()
{
flg= flg_compress;
Serial2.write(86); //0x56
Serial2.write(0); //0x00
Serial2.write(49); //0x31
Serial2.write(5); //0x05
Serial2.write(1); //0x01
Serial2.write(1); //0x01
Serial2.write(18); //0x12
Serial2.write(4); //0x04
Serial2.write(255); //0xFF
Serial2.flush();
}
void cmd_takepic()
{
flg= flg_takepic;
Serial2.write(86); //0x56
Serial2.write(0); //0x00
Serial2.write(54); //0x36
Serial2.write(1); //0x01
Serial2.write(0); //0x00
Serial2.flush();
}
void cmd_readsize()
{
flg= flg_readsize;
Serial2.write(86); //0x56
Serial2.write(0); //0x00
Serial2.write(52); //0x34
Serial2.write(1); //0x01
Serial2.write(0); //0x00
Serial2.flush();
}
void cmd_readjpeg()
{
flg= flg_readjpeg;
Serial2.write(86); //0x56
Serial2.write(0); //0x00
Serial2.write(50); //0x32
Serial2.write(12); //0x0C
Serial2.write(0); //0x00
Serial2.write(10); //0x0A
Serial2.write(0); //0x00
Serial2.write(0); //0x00
Serial2.write(0); //0x00
Serial2.write(0); //0x00
Serial2.write(0); //0x00
Serial2.write(54); //0x00
Serial2.write(pic_size1); //0x0D
Serial2.write(pic_size2); //0xB4
Serial2.write(0); //0x00
Serial2.write(10); //0x0A
Serial2.flush();
}
void cmd_stop()
{
flg= flg_stop;
Serial2.write(86); //0x56
Serial2.write(0); //0x00
Serial2.write(54); //0x36
Serial2.write(1); //0x01
Serial2.write(3); //0x03
Serial2.flush();
}
void view_picsize()
{
Serial.print("Pic size 1:");
Serial.println(pic_size1,HEX);
Serial.print("Pic size 2:");
Serial.println(pic_size2,HEX);
Serial.flush();
}
void view_piccode()
{
for(unsigned long i=5;i<numOfByte;i++)
Serial.println(feedBackString*,HEX);*

  • Serial.flush();*
    }
    //---------------------------------------------------------//
    void setup()
    {
  • Serial.begin(38400);*
  • inputString.reserve(20);*
  • Serial2.begin(38400);*
  • Serial.println("test CAM");*
  • Serial.flush();*
    }
    void loop()
    {
  • // receive command from user*
  • if (stringComplete)*
  • {*
    // Serial2.begin(38400);
  • Serial.println(inputString);*
  • Serial.flush();*
  • if(inputString=="reset."){Serial2.begin(38400);cmd_reset();}*
  • else if(inputString=="size1.") cmd_size1();*
  • else if(inputString=="size2.") cmd_size2();*
  • else if(inputString=="size3.") cmd_size3();*
  • else if(inputString=="baud9600.") cmd_baud9600();*
  • else if(inputString=="baud38400.") cmd_baud38400();*
  • else if(inputString=="compress255.") cmd_cpr255();*
  • else if(inputString=="takepic.") cmd_takepic();*
  • else if(inputString=="readsize.") {count=0; cmd_readsize();}*
  • else if(inputString=="readjpeg.") {numOfByte=0; cmd_readjpeg();}*
  • else if(inputString=="stop.") {cmd_stop();Serial2.end();}*
  • else if(inputString=="picsize.") view_picsize();*
  • else if(inputString=="piccode.") view_piccode();*
  • else*
  • {*
  • Serial.println("Command does not exist!!");*
  • Serial.flush();*
  • }*
  • inputString = "";*
  • stringComplete = false;*
  • }*
  • if(Serial2.available())*
  • {*
  • byte inChar;*
  • inChar= (byte)Serial2.read();*
  • if(flg==flg_reset)*
  • { *
  • Serial.print(inChar,HEX);*
  • flg=flg_wait;*
  • }*
  • else if(flg==flg_size)*
  • { *
  • Serial.print(inChar,HEX);*
  • flg=flg_wait;*
  • }*
  • else if(flg==flg_compress)*
  • { *
  • Serial.print(inChar,HEX);*
  • flg=flg_wait;*
  • }*
  • else if(flg==flg_takepic)*
  • { *
  • Serial.print(inChar,HEX);*
  • flg=flg_wait;*
  • } *
  • else if(flg==flg_readsize) *
  • {*
  • Serial.print(inChar,HEX);*
  • count++;*
  • if(count==8) pic_size1=inChar;*
  • if(count==9)*
  • {*
  • pic_size2=inChar;*
  • flg=flg_wait;*
  • } *
  • }*
  • else if(flg==flg_readjpeg)*
  • {*
  • feedBackString[numOfByte]= inChar;*
  • if(feedBackString[numOfByte]==217)*
  • {*
  • if(feedBackString[numOfByte-1]==255)*
  • {*
  • feedBackComplete =true;*
  • Serial2.end();*
  • Serial.println("Loading completed");*
  • Serial.println("Number of Byte:");*
  • Serial.print(numOfByte,DEC);*
  • Serial.flush();*
  • }*
  • }*
  • if(feedBackComplete) Serial.println(inChar,HEX);*
  • numOfByte++;*
  • }*
  • else*
  • {*
  • flg=flg_wait;*
  • Serial2.flush();*
  • }*
  • }*
  • while (Serial.available())*
  • {*
  • char inChar = (char)Serial.read();*
  • if (inChar != 10) inputString += inChar;*
  • else stringComplete = true;*
  • }*
    }
    void serialEvent()
    {

}
I get an error code that is when one can succeed without sending camera control commands from the Serial Monitor. My computer runs Windowns7 Ultimate 32bit and IDE 1.0.5 is used. I just tested successfully used 1 time on the computer WindownsXP sp3 version 3.1. Anyone can help me check on the code or test of a Windows operating system to upload my code above. Thank you!
Arduino_Cam.ino (6.88 KB)

taducgiang:
This is the test code to the Arduino camera SEN-10061 2560 R3.

Does your code display in italics when you view it inside the IDE? No, I didn't think so. Read the sticky at the top of this section, particular the part about how to post code.

I run this code on windows XP sp3 version 5.1 is still sending commands to control the camera down SEN-10061 in a normal way. The problem is that I can not on windows7. I have tried on many computers running Windows7 and on the IDE version as 1.0.3,1.0.4,1.0.5. You can test my code and give me comments. Thanks!

You can test my code and give me comments.

No, we can't. The code you posted improperly won't even compile.