Show Posts
Pages: 1 ... 44 45 [46] 47 48 ... 86
676  Using Arduino / Programming Questions / Re: leds are repeating top and bottom in pattern on: July 21, 2012, 02:25:32 pm
Not sure what you mean by "repeats the bottom/last".

So if the pattern is LED 3 and 5 of 5 LEDs would you expect it to blink 3, 5, (going forward) and then 5, 3 (going backward) which is what the code does very well. but you want 3, 5, 3 because the 5 is at the end, you do not want it twice?

As you write, reducing your loops would not work if the numbers are 2,3 4 in the 5 Lights as it would do 2, 3, 4, 4, 3, 2 and you want to avoid doing the 4 double?.

It requires more code: you have to remember the last LED number you blinked, and then ignore it if the same number comes up again. You can code that test & skip inside your Ledpattern function.

Lastly I am worried about your construct
Code:
if ( test ) { /* empty */ } else { /*actual code*/ }
If it is temporary construct due to some debugging code now left out, OK, but change it to
Code:
if ( opposite-test ) { /*actual code*/ }
677  Using Arduino / Programming Questions / Re: Simple-yet-powerfull - Serial Command input with numbers on: July 21, 2012, 01:17:10 pm
Hi GoForSmoke - thanks for the comment, but you are reading the test the wrong way round: the while is ONLY busy while there ARE characters in the buffer. No characters, it will return at once. Likewise if the number/command is complete. At least that is the intention. And as far as I have tested, it seems to work that way. Here is my little test.
Code:
/* Test the nnnC library */

#include "nnnC.h"

void setup() {
  Serial.begin(9600);
  Serial.println("nnnC test");
}
void loop() {
   static char C ; static int V ; static float F ;                               
   if ( nnnC( &C, &V) ) {                           
     Serial.print("Command ");Serial.print(C);     
     Serial.print(" : ");Serial.println(V,DEC);       
     }                               

// An idle LED blink-without-delay to verify nonbloking
   static unsigned long Timer = 0 ;
   static boolean OnOff = true ;
   if ( millis() - Timer > 333 ) {
     Timer = millis() ;
     digitalWrite(13,(OnOff=!OnOff)?HIGH:LOW) ;
   }
}

Graynomad: thanks for the comment about brackets. Using atoi/atof and those require using a buffer (precious RAM bytes) and suddenly there is maximum inputsize (nnnC accepts a 100 digit number - it wont fit in an integer smiley but no parser or memory overflow). I have not exactly measured it, but have experienced that including the atoi/f will appreciably increase the code size.

Any/Everybody: The design is "minimalistic": It is not foolproof (like "7-5" is legal interpreted as -75) but functional enough.
678  Using Arduino / Motors, Mechanics, and Power / Re: MC433 on: July 21, 2012, 12:45:48 pm
Hi Chagrin, no problem with doing the LPT ports, with direct connection from the Arduino. According to the schematics they go directly to the motor-controller (an ATmega48) so no problems with levels/currents there. The schematic shows a pullup on the limit switches and the doc says it only needs a pulldown to ground, so they should be OK to float (of course, simple enough to set up a pullup...)

My question is about using the TWI/I2C interface. On this interface you get to talk to motor controller to set some scaling factors, which it stores in its EEPROM and retrieves/uses on powerup.

If the only purpose is to drive the steppers I would use something else - got plenty of modern stepper-drivers. But the fun-of-the-game is this MC433 board (until it gets too difficult)
679  Using Arduino / Programming Questions / Simple-yet-powerfull - Serial Command input with numbers on: July 20, 2012, 03:58:33 pm
This is an invitation for comments by the those who feel experienced enough (you know who you are smiley )

Sometime(often) people ask here how to use the Serial input to give simple commands, possibly with some numeric argument to their sketch. The thread then revolves around ASCII <-> Integer conversion and what a "terminator" is. For my own use I have evolved the simple syntax: first the number is entered (ASCIIwise) in the Serial input and then terminated by a command character. The code accumulates so it does not block. Sending the ASCII sequence "67x3yp" would be interpreted as three commands: Command X with argument 67, command Y with argument 3 and Command P with argument 0.

Until recently I usually cut-n-paste this codesnippet in my various sketches, I have now rewritten it as a very small library for the community.

The nnnC.h module
Code:
/*--------------------------------------------------------------------------------*\
|   nnnC - Number Command input                                                    |
|                                                                                  |
|  Read serial input of simple argument values in format "nnnC"                    |
|   nnn is a series of (ASCII) digits, with optional sign (& decimalpoint for nnnF)|
|   C is a single character that is the command or argument name terminates string |
|   C is converted to uppercase.                                                   |
| Call "fffC" instead of "nnnC" for float value (See prototype declaration below)  |
|                                                                                  |
| The call is non-blocking, so command interpretation is done in its own "thread", |
| meaning : You can call it as often as you want in the loop()                     |
| Only when it returns true will the the arguments C and V contain valid values.   |
|                                                                                  |
| Example use:                                                                     |
|   static char C ; static int V ;                                                 |
|   if ( nnnC( &C, &V) ) {                                                         |
|     Serial.print("Command ");Serial.print(C);                                    |
|     Serial.print(" : ");Serial.print(V,DEC);                                     |
|     }                                                                            |
\*--------------------------------------------------------------------------------*/

/*-------------------------------------------------------------------------*\
| Not-a-bug; known limitations:                                             |
| Illegal numeric syntax, how the "-", "+" and "." are placed, are accepted |
| If you use both nnnC and fffC only "switch" between them after a command  |
| Note the parameters must be global or static                              |
| the nnnC only takes int - maximum is +/-32767 as usual                    |
| (But it is easy - just change "int" to "long" and you can do longs :-) )  |
\*-------------------------------------------------------------------------*/

#ifndef _nnnC
#define _nnnC

#if ARDUINO < 100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif

boolean nnnC( char *, int * ) ;
boolean fffC( char *, float * ) ;

#endif


The nnnC.cpp module
Code:
/*--------------------------------------------------------------------------------*\
|   nnnC - Number Command input                                                    |
|                                                                                  |
|  Read serial input of simple argument values in format "nnnC"                    |
|   nnn is a series of (ASCII) digits, with optional sign                          |
|   C is a single character that is the command or argument name terminates string |
|   C is converted to uppercase.                                                   |
|                                                                                  |
| The call is non-blocking, so command interpretation is done in its own "thread", |
| meaning : You can call it as often as you want in the loop()                     |
| Only when it returns true will the the arguments C and V contain valid values.   |
|                                                                                  |
| Example use:                                                                     |
|   static char C ; static int V ;                                                 |
|   if ( nnnC( &C, &V) ) {                                                         |
|     Serial.print("Command ");Serial.print(C);                                    |
|     Serial.print(" : ");Serial.print(V,DEC);                                     |
|     }                                                                            |
| Use "fffC" instead of "nnnC" for float value                                     |
\*--------------------------------------------------------------------------------*/

#include "nnnC.h"

// Integer version
// NB: The "." acts a command character, not part of a number.
boolean nnnC (char * Cmd, int * Val) {
  static boolean Done = true ;
  static boolean Negative = false ;
  if ( Done ) {                        // if a valid value has been returned before
    Negative = Done = false ;          //   reset for new command
    *Val = 0 ;
    }
  while ( Serial.available()>0 ) {     // interpret all serial bytes ...
    *Cmd = Serial.read() ;
  if (*Cmd == '-')                     // negative value
    Negative = true  ;                 //    set flag
    else if ('0' <= *Cmd && *Cmd <= '9') // valid digit
          *Val = (*Val) * 10 + (*Cmd) - '0' ; //    accumulate input
  else if (*Cmd == '+')                // A "+" sign
      ;                                  // ignore
    else {                              // It is a non-numeric character, i.e. the command.
      if ('a' <= *Cmd && *Cmd <= 'z') *Cmd &= B01011111 ; // forces uppercase (for 7bit ASCII)
      if ( Negative ) *Val = -*Val ;     // Adjust for negative value
      Done = true ;                      // note we are done
    return true ;                      // and exit
     }
   }
  return false ;
}

 // Float version
boolean fffC (char * Cmd, float * Val) {
  static boolean Done = true ;
  static boolean Negative  ;
  static byte Fraction ;
  if ( Done ) {                         // reset for new interpretation.
    Negative = Done = false ;
    *Val = 0 ; Fraction = 0 ;
    }
  while ( Serial.available()>0 ) {      // interpret all serial bytes ...
    *Cmd = Serial.read() ;
if (*Cmd == '-') {                  // negative value
  Negative = true ;                 //    set flag
  return false ;                    //    and exit
  }
if (*Cmd == '.') {                  // decimal point
  Fraction = 1 ;                    //    start counting, and thus flag decimal seen.
  return false ;                    //    and exit
  }
    if ('0' <= *Cmd && *Cmd <= '9') {   // valid digit
      *Val = *Val * 10 + *Cmd - '0' ;   // accumulate input
  if ( Fraction > 0 ) Fraction++ ;  // adjusting for after decimal
      return false ;                    // and exit
  }
if (*Cmd == '+')                    // Accept and ignore a "+" sign
  return false ;
// It is a non-numeric character - treated as command character
    if ('a' <= *Cmd && *Cmd <= 'z') *Cmd &= B01011111 ; // forces uppercase (for 7bit ASCII)
    if ( Negative ) *Val = -*Val ;      //adjust for negive value
for( ; Fraction > 0 ; Fraction-- ) *Val /= 10.0 ;  // divide down decimal
    Done = true ;                       // note we are done
return true ;
   }
 }

Note: This is intended as a very lightweight routine, when a simple input commandparser is needed.

(Edit: fixed a bug on float fractions, cleaned up some comments, added some brackets for clarity)
680  Using Arduino / Motors, Mechanics, and Power / Re: MC433 on: July 20, 2012, 02:43:56 pm
Update: SOC Robotics have been kind enough to send me some info - they never got round to write the doc. So I got some source to look at to work it out  smiley-eek ... this is going to take some time. smiley-neutral
681  Using Arduino / Motors, Mechanics, and Power / Re: MC433 on: July 20, 2012, 12:44:24 pm
try to reverse-engineer
Bit too much for me, I am afraid. It also uses a .dll to get at the LPT port - so the program refuses to start on a pc without a LPT.
682  Using Arduino / Motors, Mechanics, and Power / MC433 - TWI/I2C interface on: July 17, 2012, 02:43:20 am
I have this 2nd hand MC433 which I am trying to drive a CNC table with. It is designed for that. The MC433 is an old design (2006) and assumes a LPT interface for connection smiley-wink No problem for my trusty Arduino, and I am able to to step my steppers with it in a controlled fashion, but it is jittery.

One of the avenues is that the MC433 has a TWI/I2C interface and NO/Zero/nada documentation on that. The manual says it can "talk with each of the control processors to set PWM parameters, step the motors, change step sequence (wave, full or half step), change motor turn off conditions, change chop frequency and request status." which is much more than can be done withe the LPT interface (basically just step pulses). The manual concludes "The protocol used between the MC433 and an external TWI controller is described in a separate document." I have not been able to find such a document (not even on the SOC robotics own pages)

Anyone out there have any info, experience or such like?
683  International / Scandinavia / Re: Hello world! (of Arduino). Svensk i Australien on: July 17, 2012, 02:19:16 am
Välkommen!

Där är massor af "full fart" på detta forum - men det är lite trägt på "Scandinavian". Antagligen är dina engelska bra nog for at vara i Aussieland smiley så du får snabbare svar på dom andra områden på dette Forum
684  Community / Bar Sport / Re: Raspberry Pi launch farce on: July 06, 2012, 04:55:25 am
Two other links of old-meets-new - I just fell across these today, I wasnt searching.

http://www.wired.com/gadgetlab/2012/07/custom-80s_raspberry-pi-case/
http://www.designspark.com/content/raspberry-pi-vax-cluster
685  Using Arduino / Project Guidance / Re: just a little help on: July 05, 2012, 07:00:27 am
i do not speak english very well.
Fortunatly, we only need to read your written English smiley  (that was a joke)

Quote
my question is, if that can be made, of course, and if it can, if anyone can tell me some things about the pump or dripping system i am looking for
As a project just about perfect for an Arduino, in particular with a small keyboard/LCD to see/adjust the limit settings.

The Arduino is just going to turn a pump or valve on/off, irrespective of the drip/pump choice.
686  Community / Bar Sport / Re: Raspberry Pi launch farce on: July 03, 2012, 02:12:11 pm
Quote
it is the same geek/hobby/hassle again.
With the same geeks, only a bit older this time round.   smiley-razz
ROFL - that one almost brought tears to my eyes
687  Community / Bar Sport / Re: Raspberry Pi launch farce on: July 03, 2012, 12:06:44 pm
You know, looking at the specs for the BBC Micro
(and other nostalgia)

When I heard about the Pi on a mailing list a long while ago, I wrote a reply, but didn't push send. I didn't want to appear as the grumpy old man who "has seen it all before". (It was in danish so you get the translation) This was in November last year.

Oh... well, well, first I heard of that news. One cant keep up with everything.

On the other hand - the first introductory paragraph says:
What’s a Raspberry Pi?
The Raspberry Pi is a credit-sized computer that plugs into your TV and a keyboard. It’s a capable little PC ... high-definition video. We want to see it being used by kids all over the world to learn programming
.

That reminds me of the ads of the sc/mp (I had one) and the Spectrum (had one of those, too) and so on through the 70ies and 80ies. The only difference is the number of pixles on screen, and the price is (inflation adjusted) ten times lower.

(signed)The old man, smiling a little overbearingly


What I guessed was likely, but didn't write, and this thread makes it clear, is; it is the same geek/hobby/hassle again. Just with more bytes and a faster CPU.

 smiley smiley-razz smiley-mad smiley-cool smiley-yell
688  Using Arduino / Programming Questions / Re: Help Please - Arduino Serial.read() not matching Processing's Serial.write() on: July 01, 2012, 05:21:41 pm
Quote
-48 was right...
But -'0' is completely unambiguous, and does not require consulting an ASCII table.
Indeed. I was hinting at the commented out code of the OP. You could have suggested the -='0' in your answer earlier smiley-wink
689  Using Arduino / Programming Questions / Re: Help Please - Arduino Serial.read() not matching Processing's Serial.write() on: July 01, 2012, 05:10:53 pm
If your code is sending the int 1860 it will send four bytes : 00 00 07 44  ('cause that is 1860(10) represented in hex/binary/machine)
If your code is sending the string "1860" it will send four bytes 31 38 36 30 ('cause that is the ASCII codes of four characters)

The threads says you've tried both, but neither way will work with the decoding you are doing in the Arduino (-48 was right...)
690  International / Scandinavia / Re: Hjelp til å lese av ei fotocelle? on: July 01, 2012, 04:23:02 pm
I teori ganske enkelt - du putter Gnd/0v fra din fotocelle til GND på Arduinoen, og putter fotocelle output gennem to modstande på noget der giver et 12/5 forhold - f.eks. 12KOhm,4K7Ohm - til GND. Så tager du forbindelsen mellem de to modstande til et Arduino input ben (digitalt eller analog). Det kaldes en spændnings deler.
Pages: 1 ... 44 45 [46] 47 48 ... 86