element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Upcycle It
  • Challenges & Projects
  • Design Challenges
  • Upcycle It
  • More
  • Cancel
Upcycle It
Blog Preparing to Integrate Audio
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: sjsfastcar2017
  • Date Created: 19 May 2017 5:05 PM Date Created
  • Views 838 views
  • Likes 3 likes
  • Comments 3 comments
Related
Recommended

Preparing to Integrate Audio

sjsfastcar2017
sjsfastcar2017
19 May 2017

Last week, we ran into trouble concerning our audio connections. However, this week, we managed to solder and test everything, and were able to create a youtube video of our soundcard and headphones playing sound based on keyboard input. We hope to use the Edison to integrate this audio system into the clock, with the inputs as the clock’s bells which are outfitted with potentiometers affixed to buttons.

 

In addition, we worked on the external frame of the clock, attaching the potentiometer buttons which will hopefully be used next week for the values sent over I2C. We have realized that the plastic tops of the push buttons we are using are not firmly affixed to the base of the buttons, and move around too much, so we hope to either replace the buttons or reinforce them structurally so that the heavier bell exterior can sit atop them.

 

Accomplishments for the week:

 

  • Resoldered the audio connections on the mic
  • Tested to make sure that the speaker and mic works
  • Integrated all of the previous Bash Audio code together. (Can now play random music, record, and playback at the push of different buttons)

 

Future plans for audio: We want to connect to the Edison to allow us to get music from an online playlist that can be edited by the user.



We bought a USB hub to use with the Edison. Our USB hub will allow us to control multiple USB ports for the project (Which will probably come in useful)

 

Code:






Current goals:

Next week, we plan to post a blog on the completed Arduino I2C. Hopefully by that time we will have received the Edison, and will be able to make further progress in  In addition, we plan to begin closing up the clock and integrating a stepper motor to control the clock’s gears. We chose a stepper motor over a continuously rotating servo because stepper motors were easier to find and we felt it went with the spirit of upcycling to use our old materials.

We have connected the stepper motor to the Arduino. This stepper motor will be used to turn a calibration knob on the clock, so that  We are using interrupt with I2C so that the Arduino slave will send a message over I2C that a button has been pressed.

 

Image of our stepper motor working with the two arduino units. We are working on getting it to rotate counter-clockwise. An H-Bridge may be needed.

804206101_1547059647511133431.jpg

 

Code:

 

/*
* MotorKnob
*
* A stepper motor follows the turns of a potentiometer
* (or other sensor) on analog input 0.
*
* http://www.arduino.cc/en/Reference/Stepper
* This example code is in the public domain.
*/


// the previous reading from the analog input
int previous = 0;


void setup() {

}

void loop() {
  // get the sensor value


  // move a number of steps equal to the change in the
  // sensor reading
  stepper.step(100);

  // remember the previous value of the sensor

}

#include <Stepper.h>

// change this to the number of steps on your motor
#define STEPS 100

// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 2, 3, 4, 5);

#include<Wire.h>

void setup() {

Wire.begin(8);                // join i2c bus with address #8

  Wire.onReceive(receiveEvent); // register event

  Serial.begin(9600);

  Wire.onRequest(requestEvent);

attachInterrupt (digitalPinToInterrupt (BUTTON), buttonPressed, CHANGE);

  // set the speed of the motor to 30 RPMs
  stepper.setSpeed(30);
  digitalWrite(8,HIGH);

}

 

void loop() {



}

 

// function that executes whenever data is received from master

// this function is registered as an event, see setup()

void requestEvent(){

Wire.write("hello "); /* I couldn’t get it to give a sensor value might have to do with timing? If I replace it with giving the current value for a potentiometer it does work. Might have something to do with button states */

  }

void buttonPressed ()
{

int x=analogRead(5);
  if (digitalRead (BUTTON) == HIGH)
    Wire.write(“High”);

Wire.write (x);
  else
  Wire.write (“Low”);

Wire.write(x);
}



void receiveEvent(int howMany) {

  while (1 < Wire.available()) { // loop through all but the last

    char c = Wire.read(); // receive byte as a character

    Serial.print(c);

       

  }

  int x = Wire.read();    // receive byte as an integer; checking to make sure the sent value equals original

  Serial.println(x);        /*May be turned into a stability system, so we say that if two values are more than 5 values apart, we say they aren’t measured(as in the slave sends back the number received and the master sends a new number to check against the first. This is necessary because we noticed the potentiometer values during movement could greatly vary) */

}

http://www.gammon.com.au/interrupts

 

*Change* Previously, we were going to use the Arduino to run some sensors. However, we decided that running the Arduino as a slave that would report button state to the Edison when the Edison requested it was inefficient because we couldn’t have two masters (So it would be pretty inefficient to have the Edison clog up the I2C line to constantly request button state and it would be annoying if one had to press the button for longer than half a second to make the Arduino send the information). Thus, we are looking at possibilities of using the Edison for running buttons and stuff that should be changed manually while the Arduino slave will run outputs. (Such as the mechanized calibration of the clock (Does not need to happen the second something is pressed)) Apparently there is a way to run this, but it is complicated, so we would prefer to avoid it and just use an interrupt function on the Edison to look for button pushes while the rest of the code runs.

 

Expected Problems: To be truthful, audio and I2C are expected to be the most difficult parts for this project. Thus, we have to see how difficult I2C on the Edison will be at this point.



I2C stuff

We have connected the stepper motor to the Arduino. This stepper motor will be used to turn a calibration knob on the clock, so that  We are using interrupt with I2C so that the Arduino slave will send a message over I2C that a button has been pressed.

 

Code:

 

/*
* MotorKnob
*
* A stepper motor follows the turns of a potentiometer
* (or other sensor) on analog input 0.
*
* http://www.arduino.cc/en/Reference/Stepper
* This example code is in the public domain.
*/


// the previous reading from the analog input
int previous = 0;


void setup() {

}

void loop() {
  // get the sensor value


  // move a number of steps equal to the change in the
  // sensor reading
  stepper.step(100);

  // remember the previous value of the sensor

}

#include <Stepper.h>

// change this to the number of steps on your motor
#define STEPS 100

// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 2, 3, 4, 5);

#include<Wire.h>

void setup() {

Wire.begin(8);                // join i2c bus with address #8

  Wire.onReceive(receiveEvent); // register event

  Serial.begin(9600);

  Wire.onRequest(requestEvent);

attachInterrupt (digitalPinToInterrupt (BUTTON), buttonPressed, CHANGE);

  // set the speed of the motor to 30 RPMs
  stepper.setSpeed(30);
  digitalWrite(8,HIGH);

}

 

void loop() {



}

 

// function that executes whenever data is received from master

// this function is registered as an event, see setup()

void requestEvent(){

Wire.write("hello "); /* I couldn’t get it to give a sensor value might have to do with timing? If I replace it with giving the current value for a potentiometer it does work. Might have something to do with button states */

  }

void buttonPressed ()
{

int x=analogRead(5);
  if (digitalRead (BUTTON) == HIGH)
    Wire.write(“High”);

Wire.write (x);
  else
  Wire.write (“Low”);

Wire.write(x);
}



void receiveEvent(int howMany) {

  while (1 < Wire.available()) { // loop through all but the last

    char c = Wire.read(); // receive byte as a character

    Serial.print(c);

       

  }

  int x = Wire.read();    // receive byte as an integer; checking to make sure the sent value equals original

  Serial.println(x);        /*May be turned into a stability system, so we say that if two values are more than 5 values apart, we say they aren’t measured(as in the slave sends back the number received and the master sends a new number to check against the first. This is necessary because we noticed the potentiometer values during movement could greatly vary) */

}

http://www.gammon.com.au/interrupts



  • Sign in to reply
  • balearicdynamics
    balearicdynamics over 8 years ago

    Hi Daniel

    as far as I see you are at a good point. This part is well done and it was not so easy to do. I took a look to your button press detect routine. I will warn you about the risk of bouncing. Maybe the worth to use at least a software debouncer?

     

    Enrico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 8 years ago

    Nice update.

     

    Always like to see progress.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Workshopshed
    Workshopshed over 8 years ago

    Hey Daniel, good to see some progress on the clock. You should be able to run those little 24BYJ48A motors from an arduino with the Darlington driver board you get with them, a H-Bridge should not be necessary.

     

    The 24BYJ48A has a big gearbox on it so it can do approx 4075 steps per revolution. If it is behaving a little eratically then check that the pins order is actually as expected. My final thought is there are other libraries you can play with, I based my Topsy Turvy clock on the Arduino Playground - CustomStepper  from Igor Campos, it works asynchronously so you have to call "run()" in your loop. So it should play better with your interupt based code.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube