Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Help with a menu-driven program on: August 14, 2013, 05:27:19 pm
Thanks! That fixed it.
2  Using Arduino / Programming Questions / Re: Help with a menu-driven program on: August 14, 2013, 04:52:49 pm
Thanks for the replies.  I started writing the code based on what Arrch said.  I used the "Button" library to simplify my buttons, and I use the "Finite State Machine" library to implement the state machine.  Here is what I came up with:
Code:
//from http://playground.arduino.cc/Code/Button
#include <Button.h>
//from http://playground.arduino.cc/code/FiniteStateMachine
#include <FiniteStateMachine.h>

const byte NUMBER_OF_SELECTABLE_STATES = 4; //how many states are we cycling through?

//Let's setup our states
State Homescreen = State(homescreen);
State Mode1 = State(mode1);
State Mode2 = State(mode2);
State Mode3 = State(mode3);
State Credits = State(credits);

//Initialize state machine
FSM stateMachine = FSM(homescreen);

//Let's setup the buttons
Button mode = Button(A0, PULLUP);
Button start = Button(9, PULLUP);
Button finish = Button(A2, PULLUP);
Button menu = Button(A1, PULLUP);

//let's setup our limit switches
const int limitleft = 12;
const int limitright = 13;

//variable for mode button presses
byte modePresses = 0;

//variables for limit switches
int limitrightState = 0;
int limitleftState = 0;

//Let's setup the leds (later these will be motors)
const int leftPin = 10;
const int rightPin = 11;

void setup() {
  pinMode(rightPin, OUTPUT);
  pinMode(leftPin, OUTPUT);
 
  pinMode(limitleft, INPUT);
  pinMode(limitright, INPUT);
 
  Serial.begin(9600);
}

void loop() {
  if (mode.uniquePress()){
    //increment mode button presses and constrain it to [0,1,2,3,4]
    modePresses = ++modePresses % NUMBER_OF_SELECTABLE_STATES;
    switch (modePresses){
      case 0: stateMachine.transitionTo(Homescreen); break;
      case 1: stateMachine.transitionTo(Mode1); break;
      case 2: stateMachine.transitionTo(Mode2); break;
      case 3: stateMachine.transitionTo(Mode3); break;
      case 4: stateMachine.transitionTo(Credits); break;
    }
  }
  stateMachine.update()
}

//utility functions
void homescreen(){
  Serial.print("SliderController");
  Serial.print("V.1.0");
  homemotor();
}

void mode1(){       
}

void mode2(){
}

void mode3(){
}

void credits(){
}

void homemotor(){
  while(digitalRead(limitleft) != HIGH){
    Serial.print("Homing Motor...");
    digitalWrite(leftPin, HIGH);
  }
}

However, something is not working right.  When I verify the program, it returns the error "no matching function for call to 'FiniteStateMachine::FiniteStateMachine(void (&)())'"  What could be causing this?

Also, I am having trouble programming the three modes that the program will run (as shown in the outline in my previous post).  If someone could walk me through the best way to do one of them, that would be greatly appreciated.

I will post pictures soon...

Thanks again for all the help.
3  Using Arduino / Programming Questions / Help with a menu-driven program on: August 14, 2013, 12:26:20 pm
Hi,
I am building a camera slider control based on the Arduino Pro Mini.  It is going to be controlled by a 16x2 lcd and four buttons (up, down, select, and escape).  The camera slider also has two limit switches (one on each end of the slider), and one motor which will be controlled by an L298 H-bridge.  I am still waiting on some parts to arrive, but I think I have the electronics figured out.

I am having trouble with the menu system.  Basically, I want to have a main menu that shows up when the device is turned on.  From the menu, I want to be able to select and run various "programs" which will make the slider preform various movements.  I have written an outline of what I would like to accomplish:

Code:
Setup()
Display message “Homing Motor” on LCD
run motor left until limit switch 1 is hit, then stop

Loop()
Display Menu
Show title “Main Menu”
Show list
                     Mode 1
                       Run routine “mode1” when selected
                     Mode 2
                       Run routine “mode2” when selected
                     Mode 3
                       Run routine “mode3” when selected
                     Mode 4
                       Show software version number and developer information
                       return to main menu when escape button is pushed.

mode1()
if user selects “start” on lcd,
run motor right until limit switch 2 is pushed
run motor left until limit switch 1 is pushed
repeat
if user selects “stop” on lcd,
stop the motor
if user pushes escape button,
stop the motor,
return to menu,
run motor left until limit switch 1 is hit, then stop

mode2()
If user selects “Start” on lcd,
run motor right until limit 2 is hit
stop
if user selects “start” again,
run motor left until limit 1 is hit
stop
repeat
if user pushes escape button,
stop the motor,
return to menu,
run motor left until limit switch 1 is hit, then stop

mode3()
ask user for number of cycles
save number as variable “x”
if user selects “start”
run motor right until limit switch 2 is hit
run motor left until limit switch 1 is hit
repeat “x” times
If user selects “stop”
run motor left until limit switch 1 is hit, then stop
reset variable “x”
restart the routine
if user pushes escape button,
stop the motor,
return to menu,
run motor left until limit switch 1 is hit, then stop

Does anyone know how to approach a program like this?  I have seen various libraries, such as MenuBackend (http://forum.arduino.cc/index.php/topic,38053.0.html) and phi-prompt (http://liudr.wordpress.com/libraries/phi_prompt/).  While these seem to be inline with what I would like to accomplish, they seem complicated, and I am not sure where to start.

Any help would be greatly appreciated.
4  Using Arduino / Interfacing w/ Software on the Computer / Re: Controlling Arduino with Processing GUI on: December 31, 2012, 01:37:34 pm
Thanks for the help,
I understand what you are suggesting, and I think it will work quite well, but I am having trouble figuring out how to get the Arduino to read the commands from the serial port in the format that you suggested.

I know that I will have to read the data into some kind of variable, then determine what the data is and what needs to be done, but I am not sure what code to use to do this.  In the past, I have done very basic serial control where I used code like this:

Quote
 void loop() {
   
   // see if there's incoming serial data:
   if (Serial.available() > 0) {
     
     incomingByte = Serial.read(); // read the oldest byte in the serial buffer

//Preform the code to activate the stepper motor and the LEDs

    if (incomingByte == '0') {
    
      myStepper.step(14); // moves the stepper 14 steps forward
    
      delay(50); // wait 50ms
      
      myStepper.step(-14); // moves the stepper 14 steps backward



Also, what would be a simple way to convert an angle into a set number of steps?

Thanks again for all of the help.
5  Using Arduino / Interfacing w/ Software on the Computer / Controlling Arduino with Processing GUI on: December 30, 2012, 06:32:15 pm
Hi,
I am working on a project for school that involves making a spring powered launcher that has to fire a projectile a set distance by adjusting the angle and amount of tension in the spring.  I would like to make it so that I can enter a distance into a processing program on the computer, and have it automatically calculate the required angle and tension for the spring (using a pre-made equation).  I would like it to then send this data to the Arduino via USB and have it move the motors to the correct location. Finally, I would like to have a button (either real or virtual) that will fire the projectile by activating a solenoid. I already know how to interface stepper motors and solenoids to the Arduino, but I need some help with how to approach the computer side of the project. 

Any help would be greatly appreciated.

Thanks!
6  Using Arduino / Interfacing w/ Software on the Computer / Re: Controlling Arduino with PHP over serial... on: January 04, 2012, 05:30:22 pm
Do you have PHP installed, configured, and known to be working?

Have you found and installed the PHP serial class?

What operating system are you using?

There are plenty of examples on the PHP site (php.org). PHP is a lot like C, so it isn't that hard to get a PHP script to send serial data, once you have the PHP serial class installed.

Hi,
I have PHP installed and working using MAMP Server on my Mac.  I have a the php_seroal.class.php file, but I did not know that I had to install it.  How do you install a php class? I googled it, but could not find any information...

Thanks for all of the help.
7  Using Arduino / Interfacing w/ Software on the Computer / Controlling Arduino with PHP over serial... on: January 04, 2012, 04:50:29 pm
Hello,
I am trying to make a ping pong ball launcher.  I need a controller that allows me to move a stepper motor to three preset positions when I click a button on a webpage. I have made the Arduino code and circuit, and it works in that it responds when I send commands through the serial monitor. 

Here is my current Arduino Code:
Quote
#include <Stepper.h>


 int ledPin13 = 13; // the pin that the main LED is attached to
 int incomingByte;      // a variable to read incoming serial data into
 Stepper myStepper(48, 9,10,11,12); //Set up 48 step stepper motor using pins 9,10,11,12
 
 
 void setup() {
   
   Serial.begin(9600); // initialize serial communication
  
   pinMode(ledPin13, OUTPUT);  // initialize the green LED pin as an output
   
   myStepper.setSpeed(60); // 60 rpms
   
 }
 void loop() {
   
   digitalWrite(ledPin13, HIGH); //Turn on the main LED
   
   // see if there's incoming serial data:
   if (Serial.available() > 0) {
     
     incomingByte = Serial.read(); // read the oldest byte in the serial buffer

//Preform the code to switch on or off the leds

    if (incomingByte == '0') {
    
      myStepper.step(14); // moves the stepper 14 steps forward
    
      delay(300); // wait half a second.
      
      myStepper.step(-14); // moves the stepper 14 steps backward
    
  } 
   if (incomingByte == '1') {
     myStepper.step(7); // moves the stepper 7 steps forward
 }
 
   if (incomingByte == '2') {
     myStepper.step(-7); // moves the stepper 7 steps backward
  } 
   

   }
 }


I need a webpage that has three buttons.  One that says "Fire" and sends the value "0" through serial, one that says "Rapid Fire On" and sends the value "1" through serial, and one that says "Rapid Fire Off" and sends the value "2" through serial.

Does anyone know how I should go about this? I am familiar with HTML, but not PHP.

Thanks,
Andrew 
8  Using Arduino / Audio / Arduino MIDI Controller on: November 27, 2011, 05:04:37 pm
Hello,
I am trying to build a midi controller with an Arduino.  I would like to have 16 buttons that triggered a midi event when they were pushed. I would also like to have the buttons lit with an white LED all of the time, then change to blue when they are pushed. 

I know that I will need to use shift registers, such as the CD4021BE, for the buttons, and another set of shift registers, such as the 74HC595 to control the leds.

I have read the ShiftIn and ShiftOut tutorials: http://www.arduino.cc/en/Tutorial/ShiftIn and http://arduino.cc/en/Tutorial/ShiftOut, as well as how to interface with MIDI - http://arduino.cc/en/Tutorial/Midi

I have a basic understanding of how each system would work, and how to wire them up, but I have no idea how to write a program that would combine all of them into a finished product.

Thanks for the help.
9  Using Arduino / Audio / Re: Arduino Drum Machine on: September 14, 2011, 05:48:54 pm
midi data go from 0 to 127. 144 is too high.

Thanks, but it is still sending "invalid" signals... 
10  Using Arduino / Audio / Re: Arduino Drum Machine on: September 14, 2011, 03:58:08 pm
When you install the MIDI library you will also get some examples (found in the File menu Examples submenu in the Arduino SDK), like you get for most libraries you install.

But if the only MIDI you need is to send note on, you can do without the MIDI library. Or if you just want some understanding of how things work it could be a good idea to fix your code before changing to the library.

I don't have time to test (I mean, I have to leave some fun for you!) but something like this should fix your note on function:
Code:
void noteOn(byte channel, byte key, byte velocity) {
  Serial.print(0x90 & channel, BYTE);
  Serial.print(key, BYTE);
   Serial.print(velocity, BYTE);
}

And if you thought 10 was the MIDI channel to use for drums, you need to change that to 9. Channels are numbered 1 to 16, but go from 0 to 15 in the protocol.

Thanks for all the help,
I tried your new code, but I am still getting "invalid" MIDI signals.  Here is my code again:

Code:
int ledPin = 13   ;    // Led connected to digital pin 13
int piezo1 = 0   ;     // Piezo 1 connected to analog 0
byte val = 0     ;     // variable to store the value read from the sensor pin
int statePin = 0; // variable used to store the last LED status , to toglle the light
byte THRESHOLD = 60;  // threshold value to decide when the detected sound is a knock or not

void setup() 
{
 pinMode(ledPin, OUTPUT); // declare the ledPin  as OUTPUT
 Serial.begin(31250);  // set MIDI baud rate 


void loop(){
 // deal with first piezo
  val = analogRead(piezo1)/4; 
  if (val >= THRESHOLD) { 
   noteOn (9 , 144, 100);
    digitalWrite(ledPin, HIGH);
    delay(1);
    digitalWrite(ledPin, LOW);
  } 
}


// plays a MIDInote doesn't check to see that cmd is greater  than 127 or that data values are less than 127
void noteOn(byte channel, byte key, byte velocity) {
  Serial.print(0x90 & channel, BYTE);
  Serial.print(key, BYTE);
   Serial.print(velocity, BYTE);
}

Thanks again for the help.
11  Using Arduino / Audio / Re: Arduino Drum Machine on: September 12, 2011, 07:54:26 pm
I'd suggest using the MIDI library, it's much easier to use.

As to the invalid message problem, does the program actually listen for serial messages?  Because MIDI over USB is a totally different protocol (because it has to obey usb protocol) than sending MIDI directly thru a virtual serial port.  There's a serial-to-MIDI converter application available on the intarwebs, just do a google search.

As to hardware, are you looking into having velocity sensitivity?  If not, then the piezos could be wired as digital sensors, and have a trimmer pot to adjust the sensitivity.

Thanks for the quick reply, I am using a usb to MIDI cable to connect it to my computer.  I don't really care about having the pads velocity sensitive, but I am not sure how I would wire them to the Arduino as digital sensors.  I am relatively new to Arduino, and am hoping that this project will help me learn more about the Arduino.  Do you happen to know where I might find some sample code to use the MIDI library?

Thanks again for your help
12  Using Arduino / Audio / Arduino Drum Machine on: September 12, 2011, 06:26:56 pm
Hello,
I am working on building a very large drum machine.  I would like to have 16 pads that are lit with one color all of the time, but change to another color when they are struck.  I also need each pad to send a MIDI signal when they are hit.  I am going to use piezos as sensors because they are cheap and seem to work quite well.  I have started by hooking up one piezo sensor and a midi out port to the Arduino using the schematic I found here: http://todbot.com/blog/wp-content/uploads/2006/10/arduino_midi_schematic.png .

I have managed to get an LED to flash when the piezo is hit, but I am having trouble getting a MIDI signal.  I used the program "MIDI Monitor" on my mac to read what MIDI data was coming in, and it kept saying that the commands were "invalid". 

Here is the code that I am using:
Code:
int ledPin = 13   ;    // Led connected to digital pin 13
int piezo1 = 0   ;     // Piezo 1 connected to analog 0
byte val = 0     ;     // variable to store the value read from the sensor pin
int statePin = 0; // variable used to store the last LED status , to toglle the light
byte THRESHOLD = 100;  // threshold value to decide when the detected sound is a knock or not

void setup() 
{
 pinMode(ledPin, OUTPUT); // declare the ledPin  as OUTPUT
 Serial.begin(31250);  // set MIDI baud rate 


void loop(){
 // deal with first piezo
  val = analogRead(piezo1)/4; 
  if (val >= THRESHOLD) { 
   noteOn (144 , 10, 100);
    digitalWrite(ledPin, HIGH);
    delay(1);
    digitalWrite(ledPin, LOW);
  } 
}


// plays a MIDInote doesn't check to see that cmd is greater  than 127 or that data values are less than 127
void noteOn(char cmd, char data1,char data2) {
  Serial.print(cmd, BYTE);
  Serial.print(data1, BYTE);
   Serial.print(data2, BYTE);
}

I got this code from another forum thread (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1197975890)

What I am wondering is how I can fix my MIDI issue, how I can make it so that the pads are one color until they are hit, in which case they will turn another color and back again, and how I can hook up 16 pads to the 6 inputs on the Arduino.  I know that I will need to use a multiplexer for the inputs, and probably one for the outputs too (I need to use 32 separate LEDs).  I would like to use something like a 74HC4051, as they are readily available at my local electronics store.


Thank you very much for your help.
13  Using Arduino / Audio / Re: Music Syncronized MIDI controller. on: February 10, 2011, 04:47:11 pm
Is there anyway to make it so that when you push a button, it sends a preset note through a MIDI interface?  Could I not then just modify a simple LED UV meter to trigger the arduino's inputs?

Thanks again for all of the help.
14  Using Arduino / Audio / Music Syncronized MIDI controller. on: February 08, 2011, 10:09:28 pm
Hello,
I was wondering if you could help me with a project.  Our school has a lighting system that can be controlled by midi signals through a program called MyDMX.  Usually, we hook up an electronic drum kit to sync our light shows to music.  This works great for live bands, but whenever we have to play music from an iPod, we have to rely on the built in effect (ok, but not music synchronized).  What I would like to do is build a device that would listen to the music using a microphone and output MIDI signals according to the music it hears.  I have some experience in syncing lights to music using an arduino (see my Music Synchronized Traffic Light on my website at http://colvins.ca).  What I do not know how to do is make it use a microphone and operate independently from a computer.  Also, I do not know what I need to make it output to midi instead of LEDs.  

Does anyone know how I could do this?

Thanks!
Pages: [1]