Show Posts
Pages: [1] 2
1  Forum 2005-2010 (read only) / Troubleshooting / Re: Bootloader burning, bad signature,  -F on: February 14, 2009, 10:12:35 am
Is this possible using only a parallel program?

I have read the thread and this sounds like my exact problem... I have a new atmega168 chip in my Arduino Duemilanove and am getting the same signature errors when trying to burn a boot loader.

Am I able to change the bit rate of the parallel programmer to allow the boot loader to be successfully burnt? I cannot find any documentation about the file programmers.txt

If I successfully burn a boot loader would I still need to change the fuses? It sounds like I would in order to get it using the crystal and other features.

I do not have AVR studio, is this the only way to change the fuses? I suspect avrdude might be able to do it, but I have not used it before, and had not heard of fuses until about 30 minutes ago!

Any help in the right direction would be much appreciated,
Thanks.
2  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: Home and End keys on Mac OS X on: February 09, 2009, 01:26:20 pm
Yes it is an major annoyance, especially after nearly 20 years of using these keys daily in my programming, I keep doing exactly that and finding myself at either the top or bottom of the document!

And yes, home and end keys have acted like this as far as I can remember, and seem pretty standard across most operating systems; Window, Linux, BSD, the list goes on. In fact Mac OS X is the only operating system that I've used that seems to stray from the 'norm'. I'm afraid we can't blame Windows for this one smiley-wink

Anyway, custom key bindings would be ideal, even if it is just a case of adding an extra line to preferences.txt, or maybe a new file keybindings.txt

I might be able to hack in the home and end behaviour I would like to see, but it wouldn't be pretty! I don't think I could manage to read various layouts from a configuration file without a lot of research.

More and more things are making me want to move back to Linux anyway, but that's a whole other story! So I may not have this trouble much longer, but perhaps this is something to consider for a next release, sounds like a lot of Emacs users would appreciate it, and I'm sure a few Mac users too! smiley
3  Forum 2005-2010 (read only) / Bugs & Suggestions / Home and End keys on Mac OS X on: February 08, 2009, 10:57:35 am
Is it possible within the Arduino IDE on Mac OS X to make the home and end keys jump the cursor to the beginning and end of the current line, rather than the beginning and end of the document?

I have checked the preferences, configuration, and forums and have found no mention of this. Is it just me that finds this default action annoying?

I know this is how it is meant to act on OS X, but I just can't stand it. I have managed to get most other applications to act in the desired way, but the Arduino IDE seems to ignore the system wide settings (along with a few other apps), and has no options for this itself.

Am I missing something? If not can I suggest this as an option for the next release? (I see I have just missed Arduino-13)

Thanks.
4  Forum 2005-2010 (read only) / Syntax & Programs / Re: Trying to create and store an instance of a class on: March 22, 2010, 02:11:29 pm
That's it! smiley-grin That's the missing link! Thanks AlphaBeta smiley I knew there must be something simple I was overlooking.
5  Forum 2005-2010 (read only) / Syntax & Programs / Re: Trying to create and store an instance of a class on: March 22, 2010, 01:42:39 pm
Hi,

Thanks for the quick reply!

I have moved my constructor code to a begin function as suggested, but I am still getting the same compile error as before.  Even if I completely comment out all the the code inside all the functions of Relay.cpp!

It seems to be this line in the Relay.h file that's causing the problems...

    NewSoftSerial _ss;

as I think its trying to instantiate the NewSoftSerial object on construction of the Relay object, rather than waiting until I call begin() to pass it its parameters and construct it there.

In other languages I would set it to NULL in the deceleration, but this causes an error:

    NewSoftSerial _ss=NULL;

error: ISO C++ forbids initialization of member '_ss'

Do I have to use a pointer here, or can I store the actual object?

The other thing that's confusing me a bit now is how would I create the object in the begin function? Especially if i cant use the new operator?

Would I have to say:

NewSoftSerial ss(dpin_rx,dpin_tx);
_ss=ss;

or can I just do a:

NewSoftSerial _ss(dpin_rx,dpin_tx);

Or am I barking up the wrong tree?

Some example code or a link to some relevant tutorials would be very helpful smiley

Cheers
  

6  Forum 2005-2010 (read only) / Syntax & Programs / Trying to create and store an instance of a class on: March 22, 2010, 11:14:13 am
Hi all,

I'm having trouble creating and storing an instance of the NewSoftSerial class inside my own Relay class.

I'm experienced in Java and PHP, but haven't really done a lot in C++.  I think I've just about grasped pointers, but there must be something quite fundamental I'm missing here?

I have tried 2 methods, I will post the code for both...

Method 1:

--- Relay.h ---
Code:
#ifndef ATmegaNET_Relay
#define ATmegaNET_Relay

#include "WConstants.h"
#include "Module.h"
#include <NewSoftSerial.h>

class Relay : public Module{
      public:
            Relay(int dpin_tx,int dpin_rx,int timeout);
            void loop();
            void poll();
      private:
            int _timeout;
            NewSoftSerial _ss;
};

#endif

--- Relay.cpp ---
Code:
#include "WProgram.h"
#include "Relay.h"
#include <NewSoftSerial.h>

Relay::Relay(int dpin_rx,int dpin_tx,int timeout) : Module("relay"){
  _timeout=timeout;
  _ss=new NewSoftSerial(dpin_rx,dpin_tx);
  _ss.begin(9600);
}

void Relay::loop(){

}

void Relay::poll(){
  _ss.println("p");
  int timeout=millis()+_timeout;
  while(millis()<timeout){
    if(_ss.available()>0){
      char c=_ss.read();
      if(c=='#'){
        return;
      }
      Serial.print(c);
    }
  }
  Serial.println("!relay timeout");
}

This failes to compile with the following error:

/home/bob/arduino/arduino-0018/libraries/ATmegaNET/Relay.cpp: In constructor 'Relay::Relay(int, int, int)':
/home/bob/arduino/arduino-0018/libraries/ATmegaNET/Relay.cpp:5: error: no matching function for call to 'NewSoftSerial::NewSoftSerial()'
/home/bob/arduino/arduino-0018/libraries/NewSoftSerial/NewSoftSerial.h:82: note: candidates are: NewSoftSerial::NewSoftSerial(uint8_t, uint8_t, bool)
/home/bob/arduino/arduino-0018/libraries/NewSoftSerial/NewSoftSerial.h:45: note:                 NewSoftSerial::NewSoftSerial(const NewSoftSerial&)
/home/bob/arduino/arduino-0018/libraries/ATmegaNET/Relay.cpp:7: error: no match for 'operator=' in '((Relay*)this)->Relay::_ss = (((NewSoftSerial*)operator new(18u)), (<anonymous>->NewSoftSerial::NewSoftSerial(((uint8_t)dpin_rx), ((uint8_t)dpin_tx), false), <anonymous>))'
/home/bob/arduino/arduino-0018/libraries/NewSoftSerial/NewSoftSerial.h:45: note: candidates are: NewSoftSerial& NewSoftSerial::operator=(const NewSoftSerial&)

It looks like its trying to call the NewSoftSerial constructor without passing in the args, is this because I've defined it in the .h and it gets instantiated at the same time Relay is?  How would I go about declaring this property correctly?

Method 2:

I have also tried using a pointer as this compiles but seems to crash the Arduino and cause it to print out some junk and reset.

--- Relay.h ---
Code:
#ifndef ATmegaNET_Relay
#define ATmegaNET_Relay

#include "WConstants.h"
#include "Module.h"
#include <NewSoftSerial.h>

class Relay : public Module{
      public:
            Relay(int dpin_tx,int dpin_rx,int timeout);
            void loop();
            void poll();
      private:
            int _timeout;
            NewSoftSerial *_ss;
};

#endif


--- Relay.cpp ---
Code:
#include "WProgram.h"
#include "Relay.h"
#include <NewSoftSerial.h>

Relay::Relay(int dpin_rx,int dpin_tx,int timeout) : Module("relay"){
  _timeout=timeout;
  NewSoftSerial ss(dpin_rx,dpin_tx);
  _ss=&ss;
  _ss->begin(9600);
}

void Relay::loop(){

}

void Relay::poll(){
  _ss->println("p");
  int timeout=millis()+_timeout;
  while(millis()<timeout){
    if(_ss->available()>0){
      char c=_ss->read();
      if(c=='#'){
        return;
      }
      Serial.print(c);
    }
  }
  Serial.println("!relay timeout");
}

I guess the instance I created gets destroyed after the constructor exits leaving the pointer pointing at an invalid object?

As I say, theres something, probably quite simple I'm missing here... could someone point me in the right direction please?

I have tried searching but I cant seem to find a good combination of keywords!

Many thanks in advance smiley

7  Forum 2005-2010 (read only) / Exhibition / Re: SD card read/write with Arduino on: February 03, 2009, 11:44:38 am
Good point. I guess it is the little things that count when you only have a little processor and memory smiley-wink

The library is updated with that change.

Thanks again.
8  Forum 2005-2010 (read only) / Exhibition / Re: SD card read/write with Arduino on: February 03, 2009, 09:18:17 am
I had to change about two lines and now my SDWriter supports .print() and .println() in the same way Serial does, thanks to sirmorris' genius idea smiley

The new code is available in the same place at: http://code.jhodges.co.uk/SDWriter/SDWriter.zip

There is a new example in there called Print_Data that creates a CSV style file.

The old example is still there as writing byte values is still supported.
9  Forum 2005-2010 (read only) / Exhibition / Re: SD card read/write with Arduino on: February 03, 2009, 07:45:49 am
Nachtwind, and those who want it, my PHP for converting to CSV:

Code:
<?php
$packet
=array(3,2,2); //the number of bytes to read for each value of the 'packet' of data to be converted to a csv line.

$f=fopen('data.bin','r');
while(!
feof($f))&#123; //repeat until end of file
      
$csv_line='';
      foreach(
$packet AS $bytes)&#123; // loop through the packet and generate the CSV line
            
if($csv_line$csv_line.=","//append a comma if needed
            
$csv_line.=getVal($f,$bytes); //append the next value
      
&#125;
      
echo $csv_line."\n"//echo the line
&#125;

//reads $bytes bytes from file $f and convert them to a value
//does this by reading each bite as a character, and converting it to its ASCII value
function getVal($f,$bytes)&#123;
      
$val=0;
      for(
$i=0;$i<$bytes;$i++)&#123; // loop for however many bytes we require
            
$b=ord(fgetc($f)); // read a character and convert it to it's ASCII byte value with ord()
            
$val=($val<<8)+$b// shift the current value left eight bits (8 bits == 1 byte) and then add the byte we just read to the value
      
&#125;
      
return $val;
&
#125;
?>


You must adjust $packet to reflect the number of bytes used for each value. (This is currently configured to read the data generated from my example in SDWriter)

The magic of joining the bytes into larger values happens on this line: $val=($val<<smiley-cool+$b
this shifting of bits is how we join two bytes back into an int
this could also be achieved by multiplying by 256: $val=($val*256)+$b;
valbyte2byte1example values and how they would be stored in multiople bytes
255255as we probably know, 255 is the most one byte to contain
25610to store 256 or more we need another byte to store multiples of 256.  (1*256) + 0  =256
26115(1*256) + 5 =261
65535255255(255*256) + 255 = 65535  //max value of an int (2 bytes)
you could now add a third byte to store multiples of 65536
this can be done for as many bytes as you need to contain your range of numbers, with only a few more bytes you can store over billions!

sirmorris, I find the functionality of uFat is excellent and the trade-offs are not a problem, especially as it seems we are all really only wanting to log data, I can't really see the need for more functionality. If I wanted to do much more I think I would probably want a full FAT filesystem. But only the future can tell smiley-wink  

Also your method of printing to the buffer looks really cool, I haven't got time to study it greatly now, but it looks like it's exactly what JB needs and wouldn't require my suggested writeString function.  In fact I guess I could extend my SDWriter in the same way to add the print/println functionality to it smiley-grin

Thanks!
10  Forum 2005-2010 (read only) / Exhibition / Re: SD card read/write with Arduino on: February 02, 2009, 10:07:05 pm
Hi JB,

You wont be able to open it in a text editor... its saved as binary - the actual bytes rather than an ASCII representation of those numbers.

Each byte (value 0-255) in a TEXT file represents one character.  So a file containing the string "123", consists of 3 bytes of value: 49,50 and 51, which represent the characters 1,2 and 3 (see http://www.asciitable.com/)

If we write the single byte value 123 to a file we get a file which consists of 1 byte of data, value 123.  But if we view this as TEXT we will see only 1 character, a { in this case, which is represented by the value 123.  Which is why you are seeing funny characters, as a lot of the ASCII set is symbols and other weird stuff!

I will add a writeString() function to the library, but I think you would probably have trouble converting your byte's and int's to a string, I did look into this briefly (something to do with stdio.h, sprintf() and bigger code!) but quickly decided I will stick to writing values not strings to the file.

I wrote a simple PHP script that converts the raw data into a CSV.  What operating system are you using? I can share this with you, and help you with it if your on Mac or Linux, but wouldn't be able to help so much if on Windows.

I understand you want relatively user-friendly access to your data. This conversion process could be packaged into a single command or double clickable file, data.bin goes in, data.csv comes out.

It seems you are at a bit of a fork in the road, and I am not sure the best route for you. What does everyone else think? I thought string manipulation looked a little tricky in Arduino/C.  I've only had my Arduino a few weeks, also I am more used to PHP/Java/BASH. Is this conversion a sensible trade-off for avoiding strings in this case?

If you were writing lots of data, and fast, you would most certainly want to write byte values rather than ASCII strings, as this will keep file sizes much smaller and reduce the amount of time spent writing to the card (exactly what I need).

In your case trying to figure out this string thing (its actually an array of chars) might be an idea.

Let me know which route you choose.

I will add the writeString() function. Can anyone link us to any good tutorials on strings and sprintf?

11  Forum 2005-2010 (read only) / Exhibition / Re: SD card read/write with Arduino on: February 02, 2009, 08:01:08 pm
I have written a simple library based on uFat which allows you to write to the SD file as many bytes as you want at a time. It buffers the data until you have a full sector and then writes that to the card, and then starts buffering for the next sector.

You can download it from http://code.jhodges.co.uk/SDWriter/SDWriter.zip (unzip to arduino/hardware/libraries/)

I have only just finished this, and it definitely is not polished, and probably lacks some error checking. There are also some Serial.print's in the library itself that I used for testing which you will probably want to remove if you are using serial yourself.

I have posted this in its infancy as it looks like it could be of use to the posters on this thread, JB especially smiley-wink

There is a commented example of usage in there.

Hope this is of help. smiley
12  Forum 2005-2010 (read only) / Exhibition / Re: SD card read/write with Arduino on: January 24, 2009, 06:51:58 am
Excellent, now you are at the same stage that I was. Try making it retry the initialisation.  This is what fixed it for me, I changed:
Code:
 if (mmc::initialize() != RES_OK)
  {
    error(PSTR("mmc init failed.\n"));
  }
Changed to:
Code:
 while(mmc::initialize() != RES_OK){
    pprint(PSTR("mmc init failed. retrying...\n"));
    delay(100);
  }
I find it always fails once. If that doesn't fix it I am all out of ideas. Good luck.
13  Forum 2005-2010 (read only) / Exhibition / Re: SD card read/write with Arduino on: January 23, 2009, 01:21:52 pm
Mine compiled fine.

I can get a similar error if i remove the #include lines from the top of the example which makes me think its a problem with your includes.

Did you delete the files you copied to /hardware/libraries/ for version 1? they may be conflicting.
14  Forum 2005-2010 (read only) / Exhibition / Re: SD card read/write with Arduino on: January 23, 2009, 12:43:59 pm
Hi smelios,

It doesn't look like you are using the latest version, try downloading uFat2.zip rather than mmc1.rar, hopefully that will fix the problem.
15  Forum 2005-2010 (read only) / Exhibition / Re: SD card read/write with Arduino on: January 23, 2009, 09:03:48 am
Okay, I am getting somewhere...  

I thought I would try the uFat library that was mentioned fairly early on in this thread, which straightaway gave me a directory listing of all the files on this card. But hang on a minute, I thought I had formatted the card! So I popped it back into the computer, deleted all the files and created the required data.bin file, but to my amazement my new file disappeared and all the old ones came back! No amount of deleting formatting or mortifying seemed to affect this card any more, so I have scrapped it and got myself a new one.

uFat seemed very temperamental with my new card, failing to initialise nine out of 10 times. I put a simple loop round the initialising statement with a delay, so it would retry if it failed instead of just showing an error and halting. This seemed to work a treat, no matter how much delay before or after it always seems to fail once and then initialise fine on the second attempt without fail. Reading and writing then worked perfectly smiley-grin

I think I am going to stick with uFat over the raw library as it isnt any bigger and I still can't get the raw library to work even with my new card (same problems as described before), also I like being able to read my data back on the computer. smiley

The only downside is that the code for using uFat isn't as friendly as the raw library, and I can't seem to get it to write one byte at a time, it has to be written in 512byte sectors, but I can live with this.

Hopefully this information helps someone out, I am thinking to get the raw library working perhaps something needs to be inside a retry loop much like I had to do with the uFat library to get it working.

Thanks everyone who has contributed, especially agent_orange for the circuit diagram (which needs no modification to work with uFat), and sirmorris for the uFat library.
Pages: [1] 2