Difference between revisions of "Lesson 8--Microduino "Pulse Recorder""

From Microduino Wiki
Jump to: navigation, search
m (photo added)
(Video)
 
(4 intermediate revisions by one other user not shown)
Line 4: Line 4:
 
|
 
|
 
==Objective==
 
==Objective==
The lesson shows us how to use the button and aviod shaking issue. The solution is to delay time.  
+
In lesson 3, you learned how to use a button and avoid the issue of electrical noise. The solution was to add a short delay.  
But this solution has a disadvantage. As to the delay time, it all depends since it takes different time for everyone to press the button.  
+
However, this solution has a disadvantage. Different people will take different amounts of time to press a button. That means the delay must be different for different people, too.
This lesson will introduce how to get the time to press a button, the program uses pulse timing calculation.
+
This lesson will teach you how to get the duration that a button is pressed down. This program uses pulse timing calculation.
Besides that, you can learn how to use arduino's serial and monitor the data using serial.
+
In addition, you will learn about Arduino's serial port to monitor the data.
  
 
==Equipment==
 
==Equipment==
Line 13: Line 13:
 
*'''[[Microduino-FT232R]]'''
 
*'''[[Microduino-FT232R]]'''
 
*Other hardware equipment
 
*Other hardware equipment
**Breadboard Jumper            one box 
+
**1x Box of breadboard jumper wires             
**Breadboard                one piece 
+
**1x Breadboard
**Button                       one 
+
**1x Ceramic capacitor                 
**USB Data cable               one
+
**1x Button                  
 +
**1x USB Data cable
  
 
[[File:lesson8All.jpg|600px|center|thumb]]
 
[[File:lesson8All.jpg|600px|center|thumb]]
  
 
==Pulse==
 
==Pulse==
Pulse is a process that a physical quantity quickly retun to its initial state after a short time mutation.
+
Pulse is a rapid, transient change in the amplitude of a signal from a baseline value to a higher or lower value, followed by a rapid return to the baseline value.
In Microduino, pulse just a digital signal which changed between high and low in cyclical.
+
In Microduino, pulse is simply a digital signal which changes between high and low in a cyclical pattern. Pulse timing is often used to calculate the speed in electronic components.
Pulse timing is often used in the photoelectric encoder, Hall elements to calculate the speed.
 
  
==Experimental schematic==
+
==Experiment Schematic==
 
[[File:lesson8-schematic.jpg|600px|center|thumb]]
 
[[File:lesson8-schematic.jpg|600px|center|thumb]]
Using the internal pull-up, external 104 ceramic capacitors for stabilization.
+
This schematic uses the internal pull-up. We also connected an external ceramic capacitor for stabilization.
  
 
==Program==
 
==Program==
Line 43: Line 43:
 
{
 
{
 
     //Read low pulse from the pin, the maximum pulse interval is 60 seconds, and assign the result to the variable time1
 
     //Read low pulse from the pin, the maximum pulse interval is 60 seconds, and assign the result to the variable time1
   time1= pulseIn(pin, LOW,60000000)/1000;//Convert the time to ms
+
   time1= pulseIn(pin, LOW, 60000000)/1000;       //Convert the time to ms
   Serial.print(time1); //Output the time1 by serial
+
   Serial.print(time1);                           //Output the time1 by serial
 
   Serial.print("ms  ");
 
   Serial.print("ms  ");
   time2= pulseIn(pin, LOW,60000000)/1000.0;//Convert the time to ms
+
   time2= pulseIn(pin, LOW,60000000)/1000.0;       //Convert the time to ms
   Serial.print(time2); //Output the time1 by serial
+
   Serial.print(time2);                           //Output time1 by serial
   Serial.println("ms");//Through the serial port to print out the unit and wrap to a new line to output the next value.
+
   Serial.println("ms");                           //Output time2 by serial and start a new line
 
}
 
}
  
 
</source>
 
</source>
==Serial monitoring==
+
==Serial Monitoring==
 
===Open the serial port monitor===
 
===Open the serial port monitor===
*Click the Serial Monitor button, pop-up the serial monitor interface.
+
*Click the Serial Monitor button to pop-up the serial monitor interface.
 
[[File:lesson8-serialmonitor.jpg|600px|center|thumb]]
 
[[File:lesson8-serialmonitor.jpg|600px|center|thumb]]
 
[[File:lesson8-serialwindow.jpg|600px|center|thumb]]
 
[[File:lesson8-serialwindow.jpg|600px|center|thumb]]
  
 
*Note:
 
*Note:
**In order to using serial, you need add sentence "Serial.begin(xxxx)" in function setup(),xxxx is the baud rate;
+
**In order to use serial, you must add the line "Serial.begin(xxxx)" in function setup(),xxxx is the baud rate. The baud rate is the rate at which data is transferred to your computer from the [[Microduino-Core]]. The units is bits per second.
**The baud rate should be same when using the serial monitor. The baud rate is a measure of the signal transmission rate. The baud rate is not a good match, it is easy garbled.
+
**It is important that the baud rate should be set to the same number when using the serial monitor. If they do not match up, you will only see gibberish on your serial monitor.
  
*When convert the unit, need pat attention to the data type:
+
*When converting units (as in the case of microseconds to milliseconds), you need to pay attention to the data types:
 
[[File:lesson-calculate.jpg|600px|center|thumb]]
 
[[File:lesson-calculate.jpg|600px|center|thumb]]
  
===PulseIn()function===
+
===pulseIn() usage===
*Function:read a pulse(HIGH or LOW) from a pin. Such as, if the value is HIGHT, pulseIn() will start timer when pin is HIGH, then stop the timer after pin change to LOW.
+
*Function:Reads a pulse (either HIGH or LOW) on a pin. For example, if value is HIGH, pulseIn() waits for the pin to go HIGH, starts timing, then waits for the pin to go LOW and stops timing. Returns the length of the pulse in microseconds. Gives up and returns 0 if no pulse starts within a specified time out. This function is accurate for pulse ranges of 10microseconds ~ 3mins. (1s=1,000 milliseconds=1,000,000 microseconds)
The return value is the pulse time, unit is us. The timer range is 10us ~ 3mins. (1s=1000ms=1000000us)
+
*Syntax:
*Grammar:
 
 
**pulseIn(pin, value)  
 
**pulseIn(pin, value)  
 
**pulseIn(pin, value, timeout)
 
**pulseIn(pin, value, timeout)
 
*Parameters:
 
*Parameters:
**pin: pulse timing I/O port(int)
+
**pin: the number of the pin on which you want to read the pulse. (int)
**value:pulse type,HIGH or LOW(int)
+
**value: type of pulse to read: either HIGH or LOW. (int)
**timeout (optional):Wait timer for pulse timing,unit is us, the default value is 1s.(unsigned long)
+
**timeout (optional):the number of microseconds to wait for the pulse to start; default is one second (unsigned long)
  
 
==Result==
 
==Result==
For stabilization,add a 104 ceramic capacitors in signal change port, you can see a better result.
+
For stabilization, add a ceramic capacitor in the signal change port. You will be able to see better results.
 
[[File:lesson8-capacitance.jpg|600px|center|thumb]]
 
[[File:lesson8-capacitance.jpg|600px|center|thumb]]
 
[[File:lesson8Result.jpg|600px|center|thumb]]
 
[[File:lesson8Result.jpg|600px|center|thumb]]
  
 
==Video==
 
==Video==
 +
 
|}
 
|}
 
 
https://www.youtube.com/watch?v=Ge52Sx_8XeU
 

Latest revision as of 08:33, 12 July 2016

Language: English  • 中文

Objective

In lesson 3, you learned how to use a button and avoid the issue of electrical noise. The solution was to add a short delay. However, this solution has a disadvantage. Different people will take different amounts of time to press a button. That means the delay must be different for different people, too. This lesson will teach you how to get the duration that a button is pressed down. This program uses pulse timing calculation. In addition, you will learn about Arduino's serial port to monitor the data.

Equipment

Lesson8All.jpg

Pulse

Pulse is a rapid, transient change in the amplitude of a signal from a baseline value to a higher or lower value, followed by a rapid return to the baseline value. In Microduino, pulse is simply a digital signal which changes between high and low in a cyclical pattern. Pulse timing is often used to calculate the speed in electronic components.

Experiment Schematic

Lesson8-schematic.jpg

This schematic uses the internal pull-up. We also connected an external ceramic capacitor for stabilization.

Program

int pin = 2;  //Define Pin D2
float time1,time2;  //Define variables to float
 
void setup()
{
  Serial.begin(115200);  //Serial port baud rate
  pinMode(pin,  INPUT_PULLUP); //Set pin to input mode with the internal pull-up
}
 
void loop()
{
    //Read low pulse from the pin, the maximum pulse interval is 60 seconds, and assign the result to the variable time1
  time1= pulseIn(pin, LOW, 60000000)/1000;        //Convert the time to ms
  Serial.print(time1);                            //Output the time1 by serial
  Serial.print("ms  ");
  time2= pulseIn(pin, LOW,60000000)/1000.0;       //Convert the time to ms
  Serial.print(time2);                            //Output time1 by serial
  Serial.println("ms");                           //Output time2 by serial and start a new line
}

Serial Monitoring

Open the serial port monitor

  • Click the Serial Monitor button to pop-up the serial monitor interface.
Lesson8-serialmonitor.jpg
Lesson8-serialwindow.jpg
  • Note:
    • In order to use serial, you must add the line "Serial.begin(xxxx)" in function setup(),xxxx is the baud rate. The baud rate is the rate at which data is transferred to your computer from the Microduino-Core. The units is bits per second.
    • It is important that the baud rate should be set to the same number when using the serial monitor. If they do not match up, you will only see gibberish on your serial monitor.
  • When converting units (as in the case of microseconds to milliseconds), you need to pay attention to the data types:
Lesson-calculate.jpg

pulseIn() usage

  • Function:Reads a pulse (either HIGH or LOW) on a pin. For example, if value is HIGH, pulseIn() waits for the pin to go HIGH, starts timing, then waits for the pin to go LOW and stops timing. Returns the length of the pulse in microseconds. Gives up and returns 0 if no pulse starts within a specified time out. This function is accurate for pulse ranges of 10microseconds ~ 3mins. (1s=1,000 milliseconds=1,000,000 microseconds)
  • Syntax:
    • pulseIn(pin, value)
    • pulseIn(pin, value, timeout)
  • Parameters:
    • pin: the number of the pin on which you want to read the pulse. (int)
    • value: type of pulse to read: either HIGH or LOW. (int)
    • timeout (optional):the number of microseconds to wait for the pulse to start; default is one second (unsigned long)

Result

For stabilization, add a ceramic capacitor in the signal change port. You will be able to see better results.

Lesson8-capacitance.jpg
Lesson8Result.jpg

Video