Show Posts
Pages: [1] 2 3 ... 6
1  Forum 2005-2010 (read only) / Troubleshooting / Re: Compilation error with 0012 Alpha and MMC librairy on: January 29, 2009, 07:31:06 am
Hi,

Sorry to hear you're having compilation problems - the move to version 0012 broke quite a few of my sketches smiley

Are you still having the problem?
2  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: delayMicroseconds(0) on: November 15, 2007, 08:12:59 am
Then that's where the check needs to be - not in the library!
 smiley-grin
3  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: delayMicroseconds(0) on: November 14, 2007, 12:48:18 pm
Postdecrement (value--) returns the value of the variable before the operation, and thus requires a temporary value to be created to hold that different value.

think of the operation as a function:

Code:
int postdec(int& val)
{
  int temp = val;
  val = val -1;
  return temp;
}

Predecrement doesn't require the use of a compiler generated temporary and is therefore quicker, less resource hungry.

Code:
int predecrement(int& val)
{
  val = val - 1;
  return val;
}


If there was no overhead to calling a function then delay(0) might make some sense. As it is, the function would have to execute in negative time in order to return at precisely the same moment it was called smiley

I think the designers got it right. Delay(0) is pointless, and coding for it would only waste space.

Just my £0.01.

Charlie.
4  Forum 2005-2010 (read only) / Syntax & Programs / Re: help needed: functions! on: November 26, 2007, 11:06:24 am
No problem.

I'mn happy to help anytime.
5  Forum 2005-2010 (read only) / Syntax & Programs / Re: help needed: functions! on: November 11, 2007, 05:38:12 pm
Hello there.

This is a simple option, assuming that your system can always start up with the carriage going left to right.

Code:
void setup(void)
{
  // initialise the motor speed and direction, motor going right
}

void loop(void)
{
  static bool goingRight = true;

  if (goingRight)
  {
    // check rightmost endstop and if hit, reverse motor.
    {
      //  ....
    }
    goingRight = false;
  }
  else
  {
    // check leftmost endstop and if hit, reverse motor.
    {
      //  ....
    }
    goingRight = true;
  }
}

This relies on the 'static' modifier for the direction variable. It just means that the variable keeps its value in between calls. You could also make it global. Just put your end-point handling code in the appropriate places.

----

You could also step up a level and do something like the following. This is a state machine. Very simply you break your problem down into blocks (or 'states') that describe where the system is at any one time and write code to describe  these that runs each time the main loop is called.

Your problem would break down to these states: Moving right, Moving left. Easy. You could get fancier and add transitional states (hit right end stop, e-stop pressed) but let's start simple.

Here's the code. Sorry if it's not immediately understandable, but keep plugging at it and it should become clear. I'll be happy to explain further if you want. Apologies if there's any compiler errors, I haven't got access to an IDE right now. I'll fix any I find once I get a chance to test.

Code:

// this could have been done with classes but function pointers are neat and .. well I'm in that kind of mood :)
//
// this tells the compiler that we want to define a new type (like int, char, etc) the type is 'stateFunc' and it's a
// pointer to a function that returns an int and takes no parameters.
//
typedef int (*stateFunc)(void);

// here we have an array of pointers to functions.
//
stateFunc states[2];

// this is a shorthand way of assigning increasing values to labels.
//
enum
{
  LEFT_TO_RIGHT,   // will equal 0
  RIGHT_TO_LEFT    // will equal 1
};

// this doesn't need to be global, just doing this differently from 1st example.
//
int currentState;

void setup(void)
{
  // put the addresses of the functions that service each state into the array.
  //
  states[LEFT_TO_RIGHT] = leftToRight;
  states[RIGHT_TO_LEFT] = rightToLeft;

  // set up initial conditions
  //
  currentState = LEFT_TO_RIGHT;
  digitalWrite(TrackDir,LOW); // set left-to-right direction of motor
  analogWrite(MotorSpeed,200); // gives power to motor
}

void loop(void)
{
  // this is (one way) to call a function indirectly via a pointer
  //
  stateFunc theFunction = states[currentState];
  currentState = (*theFunction)();
}

int leftToRight(void)
{
  // in this state we hang out until we hit the right-hand limitswitch
  //
  if(digitalRead(RIGHT_LIMIT))
  {
    // reverse the motor and start executing the other state
    //
    digitalWrite(TrackDir,LOW); // set left-to-right direction of motor
    return RIGHT_TO_LEFT;
  }

  return LEFT_TO_RIGHT;
}

int rightToLeft(void)
{
  // in this state we hang out until we hit the left-hand limitswitch
  //
  if(digitalRead(RIGHT_LIMIT))
  {
    // reverse the motor and ... you get the picture
    //
    digitalWrite(TrackDir,HIGH); // set right-to-left direction of motor
    return LEFT_TO_RIGHT;
  }

  return RIGHT_TO_LEFT;
}


I appreciate that this second example is a lot more difficult to understand, but it's a good way to add complexity to your program without making a messy inner loop. Now that the handling of the states are passed off to functions you can go ahead and expsnd as much as you like.


Have fun with it, and don't be afraid to ask if you want to know more.

Charlie
6  Forum 2005-2010 (read only) / Syntax & Programs / Re: OOP support on: November 13, 2007, 07:57:44 am
Hi,

the system is C++ based, using avr-gcc, and within reason you can use any standard feature of the language. Remember that you're programming a limited machine and not a modern desktop machine though..!

Charlie
7  Forum 2005-2010 (read only) / Interfacing / Re: Is Deviceprint immpossible to make work? on: April 16, 2009, 07:15:43 am
Quote
Does anybody know how to make it write over the 512 bytes?

You just keep writing strings. No other action is required. You can't write a string larger than 512 bytes in one go, as this would overflow the buffer.

Glad it's working for you!

C
8  Forum 2005-2010 (read only) / Interfacing / Re: Is Deviceprint immpossible to make work? on: April 15, 2009, 10:41:39 am
Did you change the text in the sketch to try and induce an error?
Did you do anything other than click the play button?
Try setting the compiler to verbose output. The information is available  on the main site on how to do this.

9  Forum 2005-2010 (read only) / Interfacing / Re: Is Deviceprint immpossible to make work? on: April 15, 2009, 10:07:06 am
Is the board connected? Is the serial port set correctly?

Can you tell us what you have done so far to find out why this is happening? That would help a lot. If you can say that the board is connected and the IDE can communicate then that narrows things down. Can you upload other sketches? Is there smoke coming from anything?


10  Forum 2005-2010 (read only) / Interfacing / Re: Is Deviceprint immpossible to make work? on: April 15, 2009, 07:29:51 am
Indeed.

Here's is a test sketch that should give some more information:

http://groups.google.com/group/micro-hacker/web/dptest.rar?hl=en

I have copied the library code into the sketch folder to make it easier to modify. Run the sketch and report what happens. It will not work with the libraries in place. Before you load the arduino-0015 gui and this sketch, DELETE OR MOVE THE FOLLOWING DIRECTORIES AND THEIR CONTENTS:

.\arduino-0015\hardware\libraries\microfat2
.\arduino-0015\hardware\libraries\mmc
.\arduino-0015\hardware\libraries\DevicePrint

Report back on what result you get.

C
11  Forum 2005-2010 (read only) / Development / Re: Compiling an SD/MMC and fat16 library on: April 14, 2008, 07:19:04 am
The code looks good, I'll run it against my hardware and let you know what happens.

This is a long shot but could you email me a digi picture of your card with its soldered connections? I've PM'd you my email address.
12  Forum 2005-2010 (read only) / Development / Re: Compiling an SD/MMC and fat16 library on: April 14, 2008, 01:17:07 am
Here's one of the best introductions to the software side of mmc interfacing:

http://www.retroleum.co.uk/mmc_cards.html

Can you point me to the software that you use to initialise and read the card? I'll have a look over it.

13  Forum 2005-2010 (read only) / Development / Re: Compiling an SD/MMC and fat16 library on: April 13, 2008, 02:23:16 pm
Working with MMC/SD cards can be frustrating. I had a hard time making my first effort work.. smiley-sad

Are you using an MMC or an SD card? Have you tried different cards? The schematic you're using is good, you can cross-reference your work with a different version which shows the wiring for an SD socket here http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1206874649/1#0. The main difference is that this version powers the card from an Arduino's 3v3 supply whereas the version you based your circuit on is using diodes to drop the 5v to around 3v3. Other than that both card types can be addressed in the same way.

I've come in late to this conversation - what do you want to achieve? What code are you using?

14  Forum 2005-2010 (read only) / Development / Re: Compiling an SD/MMC and fat16 library on: April 13, 2008, 03:46:57 am
Hiya.

If a standard FAT library is too heavyweight for your application and you don't fancy raw card reading & writing here's a halfway-house solution that I've written:

http://arduinonut.blogspot.com/2008/04/ufat.html
 
I'm very happy to help with enhancements or explanations.
 
Charlie

15  Forum 2005-2010 (read only) / Interfacing / Re: RAM, SDCards, Memory on: November 18, 2007, 03:32:36 pm
Quote
He just wants to hook random stuff together.

LOL I have the same urge smiley-grin

Some memory modules (the 168 pin ones at least) have a serial EEPROM nailed on, ready for the scavenging. If you're confident with an iron, or unconfident but ballsy, then there's a project right there. You only need 4 wires soldered on, and away you go. check:

http://www.dewassoc.com/performance/memory/how_to_ID_memory.htm

look for SERIAL PRESENCE DETECT and have fun!

Pages: [1] 2 3 ... 6