Difference between revisions of "Example io demo"

From wiki.emacinc.com
Jump to: navigation, search
m (Added OE5 instructions)
 
(126 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{todo|InProgress(11.19.13-15:28->JG+)|Jgreene|project=oe 4,oe 5,jg,md,Review}}
+
{{todo|SEOKWREV (01.03.14-16:47->JG+);(01.03.14-17:35->MD+);(04.07.14-09:45->BS+);(04.09.14-16:15->BS+)|Jgreene|project=oe 4,oe 5,jg,md,SEOKWREV,ky,bs}}
This is a guide to the '''io demo''' C example project included in the EMAC OE SDK.
 
  
'''IO''' is an acronym; it stands for ''Input Output''. It refers to data going in and data coming out. In and out of ''what'' you ask? Why your machine of course. In this case your machine is the SOM-150ES carrier board.  
+
{{#seo:
 +
|title=io demo
 +
|titlemode=append
 +
|keywords=ADC example,Ring Counter,Binary Counter
 +
|description=This is a guide to the <code>io_demo</code> C example project included in the EMAC OE SDK.
 +
}}
 +
This is a guide to the <code>[http://git.emacinc.com/OE/qt-creator-example-projects/tree/master/io_demo io_demo]</code> C example project included in the EMAC OE SDK.
  
'''Input''' is data going into your machine. Your machine is receiving data, via a port or header, from an external piece of hardware. Mouses, joysticks, keyboards, electronic rain-guages, digital telescopes, burglar alarms and the internet: these all produce streams of data that your machine can store, process, fold, weave and/or otherwise react to. What your machine does with the data, specifically, depends what software you've got running. The '''io demo''' is an example of such software.
+
The <code>io_demo</code> project provides four examples using SOM-150ES carrier board I/O:<br />
 +
* An analog-to-digital converter demo.
 +
* A counter demo.  
 +
* An input-to-output demo.
 +
* A ring demo.
  
'''Output''' is data coming out of your machine. Your machine is sending data, via a port or header, to an external piece of hardware. It's telling that piece of hardware to do something: store some bytes of data, blink an LED, wiggle a robotic tentacle. What data gets sent depends on what software you've got running. The '''io demo''' is an example of such software.
+
The <code>io_demo</code> project builds one executable: <code>io_demo</code>.
  
Combined, that's '''IO'''. It's how your machine converses with the world outside it's solipsistic silicon kingdom. Without it your machine is just a sexy paperweight.
+
== Opening, Building and Uploading the Project Files ==
 +
 
 +
For information on opening the project from within Eclipse, please see [[Importing the EMAC OE SDK Projects with Eclipse]].  Then, follow [[Using the EMAC OE SDK Projects with Eclipse]] for information on how to build, upload and execute the example.
 +
 
 +
Alternatively, the <code>Makefile</code> can be used with the <code>make</code> command from the commandline to build and upload the example.  For more information on this method, please see [[Using EMAC OE SDK Example Projects]].
 +
 
 +
For use in EMAC SDK 5.X, please refer to the updated version of this example project: [[Libgpiod_IO_Example|libgpiod_io]]
 +
 
 +
== Usage and Behavior ==
 +
 
 +
===Hardware Requirements===
 +
 
 +
To use the '''io demo''' program you will need the following hardware.
 +
 
 +
* An EMAC [http://www.emacinc.com/som/som150es.htm SOM-150ES] carrier board. <br />
 +
* A compatible EMAC SoM for that carrier board ([http://www.emacinc.com/products/system_on_module/SoM-9260M SOM-9260M], [http://www.emacinc.com/products/system_on_module/som-9G20m SOM-9G20M] and [http://www.emacinc.com/products/system_on_module/som-9x25 SOM-9X25] are all compatible).<br />
 +
* A multimeter or oscilloscope. See [[Example_io_demo#Input_to_Output_Demo_Usage | Input to Output Demo]] and  [[Example_io_demo#Count_Demo_Usage | Count Demo]] for details.<br />
 +
* A cable long enough to reach from GPIO Port B to GPIO Port C. See [[Example_io_demo#Input_to_Output_Demo_Usage | Input to Output Demo]] for details.<br />
 +
 
 +
====Carrier Board====
 +
 
 +
[[File:know_your_som_150.jpg|frame|left|SOM-150ES carrier board with GPIO, LEDs and analog IO indicated.]]
 +
<br clear=all>
  
The '''io demo''' gives us four nice demonstrations of SOM-150ES carrier board IO. We keep it simple. As you might imagine there are some extremely sophisticated IO technologies out there (USB, Ethernet...) but that's a discussion for another time. Here we're just going to work with our general-purpose input-output header: a double row of 50 pins that can read or render a binary value. It's straightforward stuff. Understanding the principals outlined here will equip you to hold meaningful digital conversations with anything from a toaster to a space shuttle.
+
This is a detail of the '''HDR1 PLD & BUFFERED GPIO''' header. Pin 49 is Vcc. The bottom pins: 2, 4, 6...46, 48, 50; are all ground. Port A is pins 1, 3, 5, 7, 9, 11, 13, 15. Port B is pins 17, 19, 21, 23, 25, 27, 29, 31. Port C is pins 33, 35, 37, 39, 41, 43, 45, 47.  
  
== Opening, Building and Uploading the Project Files ==
+
[[File:gpio_header_detail.png]]
 +
 
 +
===io_demo Usage===
  
<big>1. Open the C/C++ editing perspective.</big>
+
Run '''io demo''' from the console. It takes no parameters.
  
stub
+
<syntaxhighlight lang="text">
 +
./io_demo
 +
</syntaxhighlight>
  
<big>2. Open the io demo project files.</big>
+
This brings up a menu of demos.<br />
 +
<syntaxhighlight lang="console">
 +
****************************
 +
    Demo Menu             
 +
                           
 +
A/D Demo            - a   
 +
Count Demo          - c   
 +
Input to Output Demo - i   
 +
Ring Demo            - r   
 +
                           
 +
Exit                - x   
 +
                           
 +
Enter Selection:
 +
</syntaxhighlight>
  
stub
+
Now, press '''a''', '''c''', '''i''' or '''r''' to run a demo; otherwise, press '''x''' to exit.
  
<big>3. Build the io demo project.</big>
+
===A/D Demo Usage===
  
stub
+
From the demo menu press '''a'''.
  
<big>4. Upload the io demo binary to the target machine.</big>
+
<syntaxhighlight lang="text">
 +
****************************
 +
    Demo Menu             
 +
                           
 +
A/D Demo            - a   
 +
Count Demo          - c   
 +
Input to Output Demo - i   
 +
Ring Demo            - r   
 +
                           
 +
Exit                - x   
 +
                           
 +
Enter Selection: a
  
stub
+
A/D Demo
 +
[0]=126 [1]=11B [2]=12C [3]=12B
 +
</syntaxhighlight>
  
== Description, Usage and Expected Behaviour ==
+
The output shows the stray charge on the inputs being read by the analog-to-digital converter on pins 11, 12, 13, 14. Press '''a''' a few times to watch the values change.
  
This is a demo program illustrating how to access different '''SOM-150ES''' carrier board io. To use this program you will need a SOM-150ES carrier board.
+
This is the HDR8 ANALOG IO header.
  
[[File:Som_150.jpeg | 500px]]<br />
+
[[File:analog_io_header_detail.jpg]]
SOM-150ES carrier board
 
  
'''Usage for io_demo'''
+
Let's do a couple of experiments on our analog in pins.
  
<code>io_demo</code>
+
Connect pin 20 to pin 11 and hit '''a'''. Note that the first value is higher than the others. It should read approximately '''3FF'''. This means that the first analog-in pin has 2.5V on it.
  
Running the program brings up a menu of demos.<br />
+
Connect pin 1 to pin 11. Hit '''a'''. Note that the first value is lower than the others. It's the vicinity of 0. That means that the first analog-in pin is pulled down to ground.
[[File:Io demo terminal menu.jpg|i2c menu]]<br />
 
Press '''a''','''c''','''i''' or '''r''' to run a demo. Press '''x''' to exit.<br />
 
  
===A/D Demo===
+
===Count Demo Usage===
  
[[File:Io demo terminal session sample 0.png]]
+
From the demo menu press '''c'''.
  
===Count Demo===
+
The system counts from 0 to 255 in binary. It takes about 15 seconds to complete.<br />
 +
The steps of this process are reflected in the GPIO PortC header pins (see [[Example_io_demo#Carrier_Board | Carrier Board]], above). As each bit in our 8-bit register is set to 1, the corresponding pin in the PortC header momentarily registers 5 volts (easily detected with a multimeter or oscilloscope).
  
Refer to the SOM-150ES carrier board surface mount LEDs LD1-LD8 for output.
+
More visibly, the counting process is also reflected in the strip of 8 LEDs on the board LD1-LD8. (see [[Example_io_demo#Carrier_Board | Carrier Board]], above). A lit LED indicates a 1 in our 8-bit register and an unlit LED indicates a 0. When the counting process is finished, all 8 LEDs are lit (255).
  
[[File:Io demo led action sample 0.png | 500px]]
+
===Input to Output Demo Usage===
  
The board counts from 0 to 15 in binary, reflecting the steps of this operation in the LEDs. When it's finished LD1 and LD6 are lit.
+
In this usage example the carrier board talks to itself. We send an 8-bit data stream directly from Port B to Port C via a short piece of cable. See [[Example_io_demo#Carrier_Board | Carrier Board]], above, for details.
  
===Input to Output Demo===
+
This is the ribbon cable for the input-to-output demo. Note that we connect PortC:pin0 to PortB:pin0; PortC:pin1 to PortB:pin1; etc.<br />
 +
[[File:iodemo_homemaderibboncable.jpg|500px|border|]]
  
Refer to the SOM-150ES carrier board surface mount LEDs LD1-LD8 for output.
+
Here's the cable plugged into the GPIO header. You see that PortC:pin0 outputs to PortB:pin0; PortC:pin1 outputs to PortB:pin1; etc.
 +
[[File:iodemo_homemaderibboncable_closeup.jpg|500px|border|]]
  
[[File:Io demo led action sample 1.png | 500px]]
+
The data stream for each pin is 1, 0, 1, 0, 1, 0... That is to say: all pins are set to 1, then they are all set to 0, then to 1 again, etc. We observe our data stream in the strip of 8 LEDs on the carrier board. They blink in unison.
  
The board lights all 8 LEDs.
+
'''Note''' The blinking may get a little out of sync after a few seconds. This is normal.
  
===Ring Demo===
+
===Usage Example. Ring Demo===
  
Refer to the SOM-150ES carrier board surface mount LEDs LD1-LD8 for output.
+
From the demo menu press '''r'''.
  
[[File:Io demo led action sample 2.png | 500px]]
+
The system sets a bit on Port C to 1, then sets it to 0, then sets the bit after that to 1, then sets that pin to 0, and so on, sequentially. This shows a ring counter on the LED strip (see [[Example_io_demo#Carrier_Board | Carrier Board]], above).
  
The board lights the LEDs in numeric sequence, 1-8, then repeats; looping until a key is pressed.
+
The steps of this process are reflected in the GPIO PortC header pins. As each bit in the 8-bit register is set to 1, the corresponding pin in the PortC header momentarily registers 5 volts (easily detected with a multimeter or oscilloscope).

Latest revision as of 13:35, 25 September 2020

TODO: {{#todo:SEOKWREV (01.03.14-16:47->JG+);(01.03.14-17:35->MD+);(04.07.14-09:45->BS+);(04.09.14-16:15->BS+)|Jgreene|oe 4,oe 5,jg,md,SEOKWREV,ky,bs}}

This is a guide to the io_demo C example project included in the EMAC OE SDK.

The io_demo project provides four examples using SOM-150ES carrier board I/O:

  • An analog-to-digital converter demo.
  • A counter demo.
  • An input-to-output demo.
  • A ring demo.

The io_demo project builds one executable: io_demo.

Opening, Building and Uploading the Project Files

For information on opening the project from within Eclipse, please see Importing the EMAC OE SDK Projects with Eclipse. Then, follow Using the EMAC OE SDK Projects with Eclipse for information on how to build, upload and execute the example.

Alternatively, the Makefile can be used with the make command from the commandline to build and upload the example. For more information on this method, please see Using EMAC OE SDK Example Projects.

For use in EMAC SDK 5.X, please refer to the updated version of this example project: libgpiod_io

Usage and Behavior

Hardware Requirements

To use the io demo program you will need the following hardware.

Carrier Board

SOM-150ES carrier board with GPIO, LEDs and analog IO indicated.


This is a detail of the HDR1 PLD & BUFFERED GPIO header. Pin 49 is Vcc. The bottom pins: 2, 4, 6...46, 48, 50; are all ground. Port A is pins 1, 3, 5, 7, 9, 11, 13, 15. Port B is pins 17, 19, 21, 23, 25, 27, 29, 31. Port C is pins 33, 35, 37, 39, 41, 43, 45, 47.

Gpio header detail.png

io_demo Usage

Run io demo from the console. It takes no parameters.

 ./io_demo

This brings up a menu of demos.

****************************
     Demo Menu              
                            
A/D Demo             - a    
Count Demo           - c    
Input to Output Demo - i    
Ring Demo            - r    
                            
Exit                 - x    
                            
Enter Selection:

Now, press a, c, i or r to run a demo; otherwise, press x to exit.

A/D Demo Usage

From the demo menu press a.

****************************
     Demo Menu              
                            
A/D Demo             - a    
Count Demo           - c    
Input to Output Demo - i    
Ring Demo            - r    
                            
Exit                 - x    
                            
Enter Selection: a

A/D Demo
[0]=126 [1]=11B [2]=12C [3]=12B

The output shows the stray charge on the inputs being read by the analog-to-digital converter on pins 11, 12, 13, 14. Press a a few times to watch the values change.

This is the HDR8 ANALOG IO header.

Analog io header detail.jpg

Let's do a couple of experiments on our analog in pins.

Connect pin 20 to pin 11 and hit a. Note that the first value is higher than the others. It should read approximately 3FF. This means that the first analog-in pin has 2.5V on it.

Connect pin 1 to pin 11. Hit a. Note that the first value is lower than the others. It's the vicinity of 0. That means that the first analog-in pin is pulled down to ground.

Count Demo Usage

From the demo menu press c.

The system counts from 0 to 255 in binary. It takes about 15 seconds to complete.
The steps of this process are reflected in the GPIO PortC header pins (see Carrier Board, above). As each bit in our 8-bit register is set to 1, the corresponding pin in the PortC header momentarily registers 5 volts (easily detected with a multimeter or oscilloscope).

More visibly, the counting process is also reflected in the strip of 8 LEDs on the board LD1-LD8. (see Carrier Board, above). A lit LED indicates a 1 in our 8-bit register and an unlit LED indicates a 0. When the counting process is finished, all 8 LEDs are lit (255).

Input to Output Demo Usage

In this usage example the carrier board talks to itself. We send an 8-bit data stream directly from Port B to Port C via a short piece of cable. See Carrier Board, above, for details.

This is the ribbon cable for the input-to-output demo. Note that we connect PortC:pin0 to PortB:pin0; PortC:pin1 to PortB:pin1; etc.
Iodemo homemaderibboncable.jpg

Here's the cable plugged into the GPIO header. You see that PortC:pin0 outputs to PortB:pin0; PortC:pin1 outputs to PortB:pin1; etc. Iodemo homemaderibboncable closeup.jpg

The data stream for each pin is 1, 0, 1, 0, 1, 0... That is to say: all pins are set to 1, then they are all set to 0, then to 1 again, etc. We observe our data stream in the strip of 8 LEDs on the carrier board. They blink in unison.

Note The blinking may get a little out of sync after a few seconds. This is normal.

Usage Example. Ring Demo

From the demo menu press r.

The system sets a bit on Port C to 1, then sets it to 0, then sets the bit after that to 1, then sets that pin to 0, and so on, sequentially. This shows a ring counter on the LED strip (see Carrier Board, above).

The steps of this process are reflected in the GPIO PortC header pins. As each bit in the 8-bit register is set to 1, the corresponding pin in the PortC header momentarily registers 5 volts (easily detected with a multimeter or oscilloscope).