Go Down

Topic: dataflash.h won't compile on my Arduino mega 2560 (Read 1 time) previous topic - next topic

KE5QDA

I downloaded "dataflash_intro" and associated library files from the playground.  I have installed a AT45DB011D on my shield and wired it correctly, changed the pin numbers in "dataflash.h".  I've been trying to get "dataflash_intro to compile for about three days and there are 19 errors all related to "dataflash.h".  Here are a few:
"Dataflash" has not been declared.
ISO C++ forbids declaration of "Dataflash" with no type
"Dataflash" is not a class or namespace
'void init ()'
"OUTPUT" was not declared in this scope

The file "dataflash.h" has only had the pin assignments changed to match the ATmega 2560.  The rest of the code is as downloaded and is quoted as being in C++.

Guess I need a little help =(

dxw00d

Quote
Guess I need a little help

You're more likely to get some help if you post the code you are trying to compile, and links to the library that you are using.

KE5QDA

Here is the code from the Arduino Playground.  And, here is the link where the library can be downloaded:  http://arduino.cc/playground/Code/Dataflash

#include <dataflash.h>

int lastpage=0; //last page written to
int pages=25; //total pages that will be used
Dataflash dflash;

void setup()
{
  Serial.begin(115200);
  Serial.print('h',BYTE);
  Serial.print('i',BYTE);
  Serial.print('\n',BYTE);//debug
  dflash.init(); //initialize the memory (pins are defined in dataflash.cpp
}

void loop()
{
  int j = 0;
  int i = 0;
  char messageline[] = "this is only a test on page: ";
  char lpstring[] = "lastpage: ";
  char int_string[10];

  itoa(lastpage, int_string, 10); // make string of the pagenumber
  strcat(messageline, int_string); //append to the messagline string
  //for (int i=0; messageline != '\0'; i++)
  while (messageline != '\0')
  {
    Serial.print(messageline, BYTE); //just a check to see if the loop is working
    dflash.Buffer_Write_Byte(1, i, messageline);  //write to buffer 1, 1 byte at the time
    j = i;
    i++;
  }
  i=0;
  dflash.Buffer_Write_Byte(1, j+1, '\0'); //terminate the string in the buffer
  Serial.print('\t');
  dflash.Buffer_To_Page(1, lastpage); //write the buffer to the memory on page: lastpage

  strcat(lpstring, int_string);
  for(int i=0; lpstring != '\0';i++)
  {
    dflash.Buffer_Write_Byte(2, 20, lpstring); //write to buffer 2 the lastpage number that was used

    Serial.print(lpstring); //write to serial port the lastpage number written to
  }
  Serial.println();
  lastpage++;
  if (lastpage > pages) //if we reach the end of the range of pages
  {
    lastpage = 0;
    for (int i=0;i<=pages;i++)
    {
      dflash.Page_To_Buffer(i, 1);//copy page i to the buffer

      for(int j=0;j<32;j++) //32 depends on the amount of data on the page
                            // testing for a specific charater is also possible
      {
        Serial.print(dflash.Buffer_Read_Byte(1, j)); //print the buffer data to the serial port
      }
      Serial.print("  page: ");
      Serial.println(i); //print the last read page number
    }
  }
  delay(200); //slow it down a bit, just for easier reading
}

dxw00d

Ok. I just downloaded it all, installed the library in the correct place, changed the WConstants.h reference in the library to Arduino.h, replaced the Serial.print(x,BYTE) statements in the sketch, and it compiled fine.

Where have you put the library files?

KE5QDA

OK, I found the library files were incorrectly named, changed "dataflash.h" to "flash.h" and all references to it.  Then, I saved "Dataflash.cpp" as "dataflash.h".  Also, I found the info on changing to <arduino.h>, but, what do you Change for BYTE.  I tried "char" and I still get a "expected primary expression before char" error on compile.  Thanks for your help in getting me going in the right direction.

dxw00d

Quote
changed "dataflash.h" to "flash.h"

I didn't need to do that.

Quote
what do you Change for BYTE.

Code: [Select]
Serial.print(x,BYTE);
changes to
Code: [Select]
Serial.write(x);

KE5QDA

Thank you, thank you, thank you!!  It compiles now.


bamboosam

WHat version of arduino are you using? Because I cant get this working for the life of me.  :smiley-eek-blue:

PaulS

Quote
WHat version of arduino are you using? Because I cant get this working for the life of me.

The psychic that we hired has not started yet. The tentative start data is the 12th of never. If you need help before then, you need to provide some more details. Like what version of the IDE you are using, and why you can't get it working - like any compiler error messages.

bamboosam

#10
Feb 28, 2013, 01:14 am Last Edit: Feb 28, 2013, 01:30 am by bamboosam Reason: 1
I tried another dataflash - AT45DB161E

It doesn't hang now: my output is:


this is only a test on page: 0  page: 0
this is only a test on page: 1  page: 1
this is only a test on page: 2  page: 2
this is only a test on page: 3  page: 3
this is only a test on page: 4  page: 4
this is only a test on page: 5  page: 5
this is only a test on page: 6  page: 6
this is only a test on page: 7  page: 7
this is only a test on page: 8  page: 8
this is only a test on page: 9  page: 9
this is only a test on page: 10  page: 10
this is only a test on page: 11  page: 11
this is only a test on page: 12  page: 12
this is only a test on page: 13  page: 13
this is only a test on page: 14  page: 14
this is only a test on page: 15  page: 15
this is only a test on page: 16  page: 16
this is only a test on page: 17  page: 17
this is only a test on page: 18  page: 18
this is only a test on page: 19  page: 19
this is only a test on page: 20  page: 20
this is only a test on page: 21  page: 21
this is only a test on page: 22  page: 22
this is only a test on page: 23  page: 23
this is only a test on page: 24  page: 24
this is only a test on page: 25  page: 25
this is only a test on page: 0   lastpage: 0
this is only a test on page: 1   lastpage: 1
this is only a test on page: 2   lastpage: 2
this is only a test on page: 3   lastpage: 3
this is only a test on page: 4   lastpage: 4
this is only a test on page: 5   lastpage: 5
this is only a test on page: 6   lastpage: 6
this is only a test on page: 7   lastpage: 7
this is only a test on page: 8   lastpage: 8
this is only a test on page: 9   lastpage: 9
this is only a test on page: 10   lastpage: 10
this is only a test on page: 11   lastpage: 11
this is only a test on page: 12   lastpage: 12
this is only a test on page: 13   lastpage: 13
this is only a test on page: 14   lastpage: 14
this is only a test on page: 15   lastpage: 15
this is only a test on page: 16   lastpage: 16
this is only a test on page: 17   lastpage: 17
this is only a test on page: 18   lastpage: 18
this is only a test on page: 19   lastpage: 19
this is only a test on page: 20   lastpage: 20
this is only a test on page: 21   lastpage: 21
this is only a test on page: 22   lastpage: 22
this is only a test on page: 23   lastpage: 23
this is only a test on page: 24   lastpage: 24
this is only a test on page: 25   lastpage: 25

This seems to be working?

bamboosam

What does the output look like when running correctly?

Go Up