Show Posts
Pages: [1] 2 3 ... 5
1  Using Arduino / Sensors / Bounce (and Bounce 2) Library Official Question Forum on: September 10, 2014, 06:06:14 pm
Bounce is a library for Arduino.
It debounces* digital inputs and more.

Bounce has passed from version 1 to version 2.
Version 2 is released but also in development.
Basically version 2 adds a better setup interface and matches the behavior requested by many (I still like the initial debounce algorithm and you can revert to the initial algorithm if you prefer).

The download is here :  https://github.com/thomasfredericks/Bounce-Arduino-Wiring/archive/master.zip
The documentation is here : https://github.com/thomasfredericks/Bounce-Arduino-Wiring/wiki
The playground page is here : http://playground.arduino.cc/code/bounce
The github is here : https://github.com/thomasfredericks/Bounce-Arduino-Wiring

Please ask questions here instead of my personal email.

* : http://en.wikipedia.org/wiki/Debounce#Contact_bounce|debounces
2  Using Arduino / Programming Questions / Re: is it just me or Bounce library is broken ? on: July 25, 2011, 03:04:26 pm
I do not know what you are expecting, but the original code works perfectly for me.
Once a change of state is detected, all future state changes are ignored for the specified time.
3  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: delayMicroseconds() bug on: September 16, 2006, 10:55:38 pm
Oh, I see in the source code that interrupts are disabled during delayMicroseconds()
Should be a warning about that!

Tom
4  Forum 2005-2010 (read only) / Bugs & Suggestions / delayMicroseconds() bug on: September 16, 2006, 10:53:28 pm
If you use delayMicroseconds, you risk data loss on the serial line.
For example, if you use the following code, some data sent is not echoed back!

Code:
char c;

void setup()
{
    Serial.begin(19200); //init the serial com
}

void loop()
{
  while (Serial.available()>0) { //check for data
       Serial.print(Serial.read()); //echo the data
  }
  
  delayMicroseconds(20000); //delay(20); //pause
  
}

If I send a lot of data, very quickly, like the following list, 1 2 3 4 5 6 7 8 9 10 11 12 13,
only some of the characters will be echoed back, for example: 1 2 8 9 10 11 12 13
(numbers 3 to 7 dissappeared, probably because they were being transfered during the pause)

If you use delay() there is no loss of data.

Tom
5  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: Size of sketch on: June 24, 2006, 01:05:51 pm
Cool!

Tom
6  Forum 2005-2010 (read only) / Bugs & Suggestions / Size of sketch on: June 23, 2006, 04:53:50 pm
I would like to know the compiled sketch size before transfering it to the Arduino Board. Is this possible?

Tom
7  Forum 2005-2010 (read only) / Syntax & Programs / Re: Removing the old serial libray:little Arduino on: August 21, 2006, 02:18:32 pm
Oh!  :o
 I recently reinstalled Arduino my Linux/Debian box, that's why version 0005.

Tom
8  Forum 2005-2010 (read only) / Syntax & Programs / Re: Removing the old serial libray:little Arduino on: August 21, 2006, 08:59:49 am
For Aduino0005, since the old serial library was not removed, you have to remove it manually.
Since the file wiring.c hanged slightly, you must add a "/*" (without the quotes) at line 217 (just before "void beginSerial(long baud)")
That way, lines 217 to 320 are commented out.

Tom
9  Forum 2005-2010 (read only) / Syntax & Programs / Removing the old serial libray:little Arduino hack on: June 23, 2006, 04:51:34 pm
A little Arduino hack...

add a "/*" (without the quotes) to line 214 of file wiring.c (in the folder "lib\targets\arduino") and get an extra 400+ bytes of programming space!
Oh and by doing this you can't use the Old deprecated serial library anymore  (see http://www.arduino.cc/en/Reference/HomePage for more info), but I think it's worth it, as the new Serial library is better.

I have been trying  to work the most punch out custom libraries lately. Just when you think your code is optimized, you compile it and discover it's larger than your previous version.

One thing I discovered, it's usually better to use more memory for variables, than using more functions.

Tom
10  Forum 2005-2010 (read only) / Syntax & Programs / Re: multiple variables from Max to Serial.read() on: June 15, 2006, 03:59:03 pm
Okay, had some time to check your code.
I think the main problem was that you are using two encodings of the serial data: ascii encoding and raw bytes (no encoding).

I also slimmed the size of the code and added a functin to make sure the servos get updated every 20 ms.
WARNING: the code is getting big, add one line of code and it might crack!

Here is the ARDUINO code:
Code:
// :::pins:::

//targetLoopDelay() vars
unsigned long previousmillis;
int delaytime;

//INPUT PINS
#define UP 2 //wit -joystick up
#define RP 3 //bruin -joystick right
#define DP 4 //blauw -joystick down
#define LP 5 //groen -joystick left
#define KP 6 //oranje -joystick button
//#define sP 0; //this is confusing... do not use digital pin 0 as it is tied to the serial line
#define rP 9 //red button
#define gP 8 //green button

//OUTPUT PINS
//int Se0 = 13; //I preffer to use pin 13 for a LED as it has an internal current resistor
#define  Se0 12        
#define  Se1 7
#define  Se2 10
//int led0 = 12;
#define  led0 13



char lastRead0;  // remember the previous input
char lastRead1;
char lastRead2;

char id;
char data = 0;

// :::functions:::

// move servo takes values that range from 0 to 255
void moveServo( char servoPin, char inputVal){
  //moving the servo's to the selected value with microsecond function
  int val;
  val = (inputVal * 4) + 1000;
  digitalWrite(servoPin, HIGH);  
  delayMicroseconds(val);      
  digitalWrite(servoPin, LOW);  
  //delay(20);
}

int simVal( char val1, char val2 ) {
  char difference;
  difference = val1 - val2;
  if (abs(difference) < 2){
    return 1;
  }
  else{
    return 0;
  }
}

void targetLoopDelay(int target_time) {

  delaytime = millis() - previousmillis;
  if (delaytime < target_time) delay(target_time - delaytime);

  previousmillis = millis();

}

void messagestart(char letter) {
  Serial.print(letter,BYTE);
}

void messagedata(char value) {
  Serial.print(32,BYTE);
  Serial.print(value,DEC);
}

void messageend() {
  Serial.println();
}

void setup() {


  pinMode(LP, INPUT);
  pinMode(UP, INPUT);
  pinMode(RP, INPUT);
  pinMode(DP, INPUT);
  pinMode(KP, INPUT);
  pinMode(rP, INPUT);
  pinMode(gP, INPUT);

  pinMode(Se0, OUTPUT);
  pinMode(Se1, OUTPUT);
  pinMode(Se2, OUTPUT);
  pinMode(led0, OUTPUT);

  moveServo(Se0, 0); // Startpositions
  moveServo(Se1, 0);
  moveServo(Se2, 0);

  digitalWrite(13, HIGH);

  beginSerial(9600);

  previousmillis = millis(); //targetLoopDelay() init
}

void loop() {
  //knoppen data doorgeven:::

  messagestart('b');
  messagedata(digitalRead(LP));
  messagedata(digitalRead(RP));
  messagedata(digitalRead(DP));
  messagedata(digitalRead(UP));
  messagedata(digitalRead(KP));
  messagedata(digitalRead(gP));
  messagedata(digitalRead(rP));
  messageend();


  //data vanuit max:::
  // loop and do if there is one or more  PAIRS of bytes
  while ((Serial.available() > 1)){

    id = Serial.read();
    data = Serial.read();

    //servo 0:
    if (id == 0) {  
      if ( !(simVal(data,lastRead0))) {
        moveServo( Se0, data );
      }
      lastRead0 = data;
    }
    //servo 1:
    if (id == 1) {

      if ( !(simVal(data,lastRead1))) {
        moveServo( Se1, data );
      }
      lastRead1 = data;
    }
    //servo 2:
    if (id == 2) {

      if ( !(simVal(data,lastRead2))) {
        moveServo( Se2, data );
      }
      lastRead2 = data;    
    }

    //led0:
    if (id == 3){

      //removed simval because it made no sense here
      if (data != 0){
        digitalWrite(13, HIGH);
      }
      else{
        digitalWrite(13, LOW);
      }
    }

  }

  targetLoopDelay(20); //this is the target delay needed for the servos

}



Here is the max patch (saved as text):

Code:
max v2;
#N vpatcher 20 96 667 639;
#P window setfont "Sans Serif" 9.;
#P newex 34 466 26 9109513 print;
#P newex 18 412 27 9109513 t b b;
#P newex 38 437 29 9109513 timer;
#P message 160 430 101 9109513 1 0 0 0 0 0 0;
#P newex 160 400 54 9109513 prepend set;
#P newex 161 339 58 9109513 fromsymbol;
#P newex 160 365 34 9109513 route b;
#P comment 227 70 100 9109513 0-255;
#P number 225 89 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 173 45 100 9109513 0-255;
#P number 171 64 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 111 25 100 9109513 0-255;
#P number 109 44 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 197 131 38 9109513 pak 2 0;
#P toggle 18 126 15 0;
#P newex 18 99 44 9109513 loadbang;
#P newex 18 149 39 9109513 metro 1;
#P newex 123 236 44 9109513 sel 10 13;
#P newex 153 270 52 9109513 zl group 64;
#P newex 141 302 151 9109513 itoa;
#P toggle 298 107 15 0;
#P newex 270 131 38 9109513 pak 3 0;
#P newex 123 203 102 9109513 serial com5 9600 8 1 0;
#P newex 143 131 38 9109513 pak 1 0;
#P newex 81 131 38 9109513 pak 0 0;
#P comment 229 202 100 9109513 Select the serial port to which you connected the Arduino;
#P comment 316 106 100 9109513 Led (#3);
#P comment 161 453 100 9109513 Buttons (b);
#P connect 12 0 13 0;
#P connect 13 0 11 0;
#P connect 21 0 26 0;
#P connect 25 0 27 0;
#P connect 26 0 25 0;
#P connect 26 1 25 1;
#P connect 15 0 3 1;
#P connect 6 0 5 0;
#P connect 11 0 5 0;
#P connect 3 0 5 0;
#P connect 4 0 5 0;
#P connect 14 0 5 0;
#P connect 5 0 10 0;
#P connect 9 0 8 0;
#P connect 10 2 9 0;
#P connect 10 1 9 0;
#P connect 22 0 21 0;
#P connect 21 0 23 0;
#P connect 23 0 24 0;
#P connect 8 0 22 0;
#P connect 17 0 4 1;
#P connect 19 0 14 1;
#P connect 7 0 6 1;
#P pop;

Tom
11  Forum 2005-2010 (read only) / Syntax & Programs / Re: multiple variables from Max to Serial.read() on: June 11, 2006, 06:42:35 am
I am workin on something similar.
2 suggestions:
A- Use "while (Serial.available() > 1)" instead of "if (Serial.available() > 1)" (or the buffer could overflow)
B- send ascii values for the integers instead of sending the raw numbers. This will give you more resolution and will ensure that "X" or "Y" do not get confused with the raw numbers.

You can check my work in progress on my Message lib here (it works): http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1149986873

From max you can send something like: "servo 5 1560" followed by a carriage return
The Message lib will split the message so you can interpret it as three elements: servo,5 (pin 5) and 1560 (ms)

Tom
12  Forum 2005-2010 (read only) / Interfacing / Messenger vs Firmata vs Bitlash on: December 07, 2009, 11:36:32 am
Library
Messenger
Firmata
Bitlash
Aprox. Size
3k
7k
14k
Out of the box solution
No
Yes
Yes
Best for
Customization. Simple string support.
Simple access to reading and setting pins. Can be customized but requires the use of Firmata's callback functions. This may break the support with the host library.
Quick prototyping. Showing off with real-time programming.
Host library
Can use the host's standard string  parsing commands. A simple library is provided for Processing and Max fo ranyone who does not want to learn how to parse strings. This library does not have to be continuously updated.
Requires a matching library on the host software. Must update the library for every new version of Firmata.
Can use the host's standard string parsing commands.
Speed
A bit slower than Firmata, but it really depends on your custom code.
Fastest
Slowest (but it is still fast!)
13  Forum 2005-2010 (read only) / Interfacing / Re: Messenger into max msp on: December 02, 2009, 12:00:10 pm
Hi,

the message
Quote
avrdude: usbdev_open(): did not find any USB device "usb"
has nothing to do with the Messenger library. You seem to be having another problem.

Please note, that you cannot program your Arduino while Max is using the serial port.

If you want the simplest solution (by that I mean not using any custom Arduino C code) to read analog pins in Max, use my version of Firmata instead (load my version of Firmata into your Arduino and launch the Max example from Max):
http://132.208.118.245/~vitamin/tof/pmwiki/uploads/Arduino/firmata.zip
14  Forum 2005-2010 (read only) / Interfacing / Re: Messenger into max msp on: November 27, 2009, 09:57:03 am
Are you still trying to figure this out?
15  Forum 2005-2010 (read only) / Interfacing / Re: messenger library and processing on: November 27, 2009, 09:53:16 am
I made a matching Messenger library for Processing, so if anybody needs it just send me a message. It will be included in the next release of Messenger
Pages: [1] 2 3 ... 5