Show Posts
Pages: [1] 2 3
1  Forum 2005-2010 (read only) / Troubleshooting / Re: Trouble saving files with 0013 A on Xubuntu 8.10 on: March 24, 2009, 10:47:20 pm
Yes, I just tried your suggestion and saving seems to work consistently if I mouse-click on the "Save" button instead of hitting Enter.
2  Forum 2005-2010 (read only) / Troubleshooting / Trouble saving files with 0013 A on Xubuntu 8.10 on: March 24, 2009, 12:03:10 am
Hello everyone, I'm having trouble saving sketches to the Sketchbook directory while running the Ardunio environment on Xubuntu.  When I try to save a project using "Save As", I often get a message that says  "You can't fool me - the new sketch name and location is the same as the old I ain't not doin' nothin' not now."  This message will pop up no matter what name I try to give the project, but often after I try four or five times it will allow me to save the project.  Does anyone have any idea what's going here?  :-?
3  Forum 2005-2010 (read only) / Bugs & Suggestions / Parenthesis checking and commented out code on: June 20, 2009, 05:34:34 pm
I'm not sure if this is a "bug" or a "feature", but the parenthesis checking in the Arduino IDE includes commented out code inside a function when doing the checking.  This might be intentional, but it is an annoyance for me!  ;D
4  Forum 2005-2010 (read only) / Syntax & Programs / Using parts of Arduino library with Eclipse? on: April 02, 2010, 04:08:15 am
I'm starting work on a largish microcontroller project, and I'm unfortunately finding the Arduino IDE too limiting in regards to managing the source code effectively.  I'd like to use the Eclipse IDE, but unfortunately so far I've been unable to get it to work with the Arduino, so I'm thinking of just doing the project with plain avr-g++ and a regular ATMega programmed via AVRDude.

I'm wondering if there's any reason I wouldn't be able to drag along a couple of useful Arduino functions? There are some libraries I have I'd like to use that use Arduino IDE functions, specifically digitalWrite and analogRead, etc, that would need to be rewritten without those functions.  Is there any reason that I wouldn't be able to just grab the Wiring libraries from the Arduino "cores" folder and compile them alongside my program to get access to those functions?
5  Forum 2005-2010 (read only) / Syntax & Programs / Re: Having a lot of trouble creating a library on: November 14, 2009, 05:21:03 am
I managed to get it to work after digging around the forums a bit - I tried deleting the object file in the library directory, then restarting the Arduino environment.  No more errors using the functions except for some warnings on compile which I'm going to have to correct in the main code.
6  Forum 2005-2010 (read only) / Syntax & Programs / Having a lot of trouble creating a library on: November 14, 2009, 04:52:17 am
Hey everyone - for a project I'm working on I need to have several small FIFO buffers and I thought I'd try to implement it as a C++ class to get some experience with that aspect of C++.  Unfortunately I'm having a terrible time trying to get the library to work in a sketch.  Here is the code in question, first the header:

Code:
#include "WProgram.h"


#ifndef Buffer_h
#define Buffer_h

struct BufferStructure;
typedef struct BufferStructure *Buffer;

class FIFOBufferClass {
public:
 

  
   byte CheckEmpty(Buffer B);
   byte CheckFull(Buffer B);
   Buffer CreateBuffer(byte Size);
   void DisposeBuffer(Buffer B);
   void EmptyBuffer(Buffer B);
   void LoadBuffer(byte data, Buffer B);  
   byte ReadBuffer(Buffer B);
private:
  
    byte Succ(byte Value, Buffer B);

};

#endif

And the .cpp file:

Code:
#include <stdlib.h>
#include "WProgram.h"
#include "Buffer.h"


#define MIN_SIZE 5

struct BufferStructure
{
  byte Capacity;
  byte Front;
  byte Rear;
  byte Size;
  byte *Array;
};



byte FIFOBufferClass::CheckEmpty(Buffer B)
{
  return B->Size == 0;
}

byte FIFOBufferClass::CheckFull(Buffer B)
{
  if (B->Size == B->Capacity)
  return 1;
}

Buffer FIFOBufferClass::CreateBuffer(byte Size)
{
  Buffer B;
  
  if (Size < MIN_SIZE)
      Serial.print("Buffer Size Too Small!");  

  B = (Buffer)malloc(sizeof(struct BufferStructure));
  if (B == NULL)
      Serial.print("Out of Memory!");
      
  B->Array = (byte*)malloc(sizeof(byte)*Size);
  if (B->Array == NULL)
      Serial.print("Out of Memory!");
      
  B->Capacity = Size;
  
  EmptyBuffer(B);
  
  return B;
 
}
void FIFOBufferClass::DisposeBuffer(Buffer B)
{
  if (B != NULL)
  {
    free(B->Array);
    free(B);
  }

}

void FIFOBufferClass::EmptyBuffer(Buffer B)
{
   B->Size = 0;
   B->Front = 1;
   B->Rear = 0;
}

void FIFOBufferClass::LoadBuffer(byte data, Buffer B)
{
    if(CheckFull(B))
      Serial.print("Buffer is full!");
    else
    {
       B->Size++;
       B->Rear = Succ(B->Rear, B);
       B->Array[B->Rear] = data;  
    }  
}

byte FIFOBufferClass::ReadBuffer(Buffer B)
{
    byte data;

    if(CheckEmpty(B))
       Serial.print("Buffer is empty!");
    else
    {
        data = B->Array[B->Front];
        B->Size--;
        B->Front++;
        return data;
    }
}
  
 byte FIFOBufferClass::Succ(byte Value, Buffer B)
{
    if (++Value == B->Capacity)
        Value = 0;
    else
        Value++;        
    
    return Value;  
}

The problem is when I include this library in a sketch, create an instance of the class, and then try to call any member function of the class I always get the following kind of error: "undefined reference to 'FIFOBufferClass::CreateBuffer(unsigned char)", no matter what function I try to call.  Can anyone see where I've gone wrong?  :'(

Edit: Here is the main sketch:

Code:
#include <Buffer.h>

void setup()                    
{
  FIFOBufferClass TestClass;
  Buffer TestBuffer;
  
  TestBuffer = TestClass.CreateBuffer(10);
  
  
}

void loop()                    
{
 
}
7  Forum 2005-2010 (read only) / Syntax & Programs / Using the Flash memory to store a lookup table on: August 11, 2009, 03:04:10 am
Hey everyone, I have a sketch in which I need to store a static lookup table for use by the program at various points.  However, it's too large to fit in RAM - too large to fit in the EEPROM also.  I do have plenty of flash memory space left - is there a straightforward way I can go about writing the array to the onboard flash memory? I don't need to modify the data at all while the program is running, I just need to be able to put it in at compile time and read it when the program is running.

Edit: I found this after hunting around more, which seems to be exactly what I need! http://www.arduino.cc/en/Reference/PROGMEM

My only concern which I'm not completely clear on is whether the data has to first fit in the RAM before it is written out of the RAM and into Flash.  If this is the case, it could be a problem.  :-?
8  Forum 2005-2010 (read only) / Syntax & Programs / Re:  Looking for a location for user-created headers on: July 17, 2009, 01:02:46 am
Sorry for the delay in my reply, I had been on vacation for a while.  I've come back to this problem, and unfortunately I still can't get adding files to the sketch to work.  Putting it in my libraries folder as a .h file doesn't work (no such file or directory), and when I select "Add File" from the Sketch menu and select the file I want to add, no tab is added - nothing happens at all.  Any ideas?  

Edit: I have it working now, I found the little arrow button at the far right of the environment (couldn't see it hiding over there!) and created a tab, then pasted in my data.  Unfortunately, I've hit another problem, in that when I declare arrays or variables in this new tab the main sketch file doesn't "see" them when it compiles and I keep getting "not declared in this scope" errors.

Edit again: If I declare the arrays in both the main program and the tab, I get a variable redefinition error...if I declare the arrays just at the top of the main program, everything compiles fine. So it seems like maybe there's some kind of ordering issue with the compiler where it's looking at the main program first and causing an error when it hasn't yet looked at the tab where the variables are defined?  :-?
9  Forum 2005-2010 (read only) / Syntax & Programs / Re:  Looking for a location for user-created headers on: July 08, 2009, 03:20:09 am
Quote
I don't see how two arrays can clutter up code.

They're wavetables for direct digital synthesis - each array has 255 1 byte values, and I eventually will need 4 of them.  It's a lot of stuff to have sitting at the top of my sketch... :o
10  Forum 2005-2010 (read only) / Syntax & Programs / Looking for a location for user-created headers on: July 08, 2009, 02:15:39 am
Well, I've run into another problem now that I've got my problem with assigning pointers to elements of arrays straightened out.  I'm dealing with a couple of large arrays of numbers, and I was hoping to store them in a header file so they wouldn't clutter up the code, however when I put the header file in the sketch directory and do #include "arrays.h" the compiler can't find it.  Any ideas?
11  Forum 2005-2010 (read only) / Syntax & Programs / Re: Structures, pointers to structures, and bytes on: July 18, 2009, 03:08:27 pm
I also thought that I could do it the second way in AWOL's example, but I always get "a_structure was not declared in this scope" errors when I try to do it that way...
12  Forum 2005-2010 (read only) / Syntax & Programs / Re: Structures, pointers to structures, and bytes on: July 18, 2009, 01:38:38 am
Yes, you're right. I was putting the parts of the code relative to the problem from memory (since the code is large and I wanted to make the issue clear), and I forgot some significant parts!  :'( It should have been like this:
Code:
typedef struct my_struct {

byte data1;
byte data2;
byte data3;

} a_structure;

a_structure structure1;

DoStuff(&structure1);

void DoStuff(struct my_struct *editingStructure)
{

editingStructure->data1 = 100;

}


That should be beter!  In any case, I figured out the problem, I had a facepalm kind of mistake in the function where I assign initial values to the structure in question.  Everything is working fine now!  I suppose if anyone wants to use structure types and pointers in their code, they could use something like the above as an example.  smiley-grin For some reason you have to add the "my_struct" to the type definition and "struct my_struct" to the function call to get the compiler to like it, which isn't how I remember doing it in C - I'm not sure exactly why this is...
13  Forum 2005-2010 (read only) / Syntax & Programs / Structures, pointers to structures, and bytes on: July 18, 2009, 12:26:08 am
I'm having a bit of a problem with one of my sketches - if I do the following:
Code:

typedef struct my_struct {

byte data1;
byte data2;
byte data3;

} a_structure;

a_structure structure1;

structure1->data1 = 100;


Whenever I try to access or modify the data in "structure1" I can never get it to return anything but 0.  When I use an integer type for the data values inside the structure, however, everything works as expected.  I'd really like to use byte types for the data inside the structure, as I intend on having several of them in this sketch and would like to keep the memory usage down.  Any ideas on what's going on?  :-?
14  Forum 2005-2010 (read only) / Syntax & Programs / Re: pointer declaration error on: July 08, 2009, 01:32:21 am
Excellent, I think I've got it straightened out now! Thanks!  ;D
15  Forum 2005-2010 (read only) / Syntax & Programs / Re: pointer declaration error on: July 08, 2009, 12:45:14 am
Maybe the following example, based on that of Coding Badly, can help you all clear up my confusion:

Code:
byte my_array[255];
byte *myPtr;

void setup()
{
  myPtr = &my_array[0];

}

void loop()
{
  
  stuff();

}

void stuff()
{

  myPtr+=1;

}

Now, if I do that, will myPtr be pointing to the address of the second value of my_array?  Or will it be pointing to something random, because myPtr is only declared to point to the address of the first item in my_array inside setup()? I don't want to put myPtr = &my_array[0]; inside the loop() function, because I don't want the pointer variable to be reinitialized to the first item in my_array every time I go through the loop.  That's why I tried to use that assignment outside of both setup() and loop(), but it wouldn't compile that way.
Pages: [1] 2 3