Skip to content

Example 03: Multiplexed signal readings

Alexander Spiridonov edited this page Oct 13, 2016 · 21 revisions

Additional documentation for an example supplied with the KeyDetector library that demonstrates how to encode digital signal into single analog line and decode it using library.

About

This is more of a real life example. Imagine you want to control your project with wireless controller, such as, for example, PS3 DualShock 3 or Navigation Controller. You decided to use USB Host Shield Library 2.0 with compatible USB Host shield for your Arduino and a Bluetooth dongle. There are quite a bit of documentation out there on how to achieve that, and a basic example that comes with USB Host Shield Library 2.0.

Now, what if for some reason you decided to divide your project into two parts (or modules): Control module, responsible for interaction with PS3 controller, and Main module, which will hold primary logic of your sketch? This may be an option in case, for example, when there are simply not enough space left for your own primary sketch after including USB Host Shield Library 2.0. Or you just prefer systems comprised of modules, which can be upgraded independently from one another.

So you’re left with two modules that need to be somehow connected in order for Main module to receive data from Control module. If you find yourself in a situation with limited pin-budget, you may want to multiplex control signals from digital buttons of your controller (connected to Control module) into single analog line. That way you’ll be able to connect modules with (almost) only one wire (not counting power and GND wires as well as any other analog signals you may want to transmit from the controller, such as stick coordinates).

In this example we’ll see how to encode (or multiplex) digital signals into analog signal as well as how to decode (or demultiplex) it back on the receiving end using KeyDetector library. Additionally we’ll transmit signals form analog stick of the PS3 controller with the use of PWM to analog conversion.

Note: in order to proceed with this example it’s highly recommended that you’ll get familiar with how to use USB Host Shield Library 2.0 and how to set it up to operate with Bluetooth connected controller.

Parts List

  • Arduino equipped with ATmega328 controller (UNO, Pro, Pro Mini, etc.); Arduino Pro Mini (ATmega328/3.3V/8MHz) was used in the example
  • USB Host Shield compatible with aforementioned Arduino; USB Host Shield for Arduino Pro Mini was used in the example
  • Controller (PS3 DualShock 3, Navigation Controller or compatible)
  • Compatible Bluetooth dongle; HAMA H-104890 was used in the example
  • Arduino UNO or compatible
  • Two 10kOhm resistors
  • Four 20kOhm resistors
  • Two 1MOhm resistors
  • Two 100nF capacitors

Multiplex

First, lets assemble Control module. Attach USB Host Shield to your Arduino equipped with ATMega328 controller. Arduino Pro Mini was used in this example, however it may be similar or compatible board. Restriction to use ATMega328 is essential because of specific direct port manipulation used in the example. Connect your controller via Bluetooth to USB Host Shield (refer to appropriate guides on how to do that) and make sure your set up is working (use basic examples that come with the USB Host Shield Library 2.0 for testing). PS3 Navigation Controller was used in this example (DualShock 3 should also work without the need for altering the source code).

This set up will provide us with the way to detect presses of controller buttons and get coordinates of its analog joystick. Now we need a way to transmit this data to the adjacent Arduino, which forms Main module. One possible way to do this is to use multiplexing.

Multiplexing here is essentially encoding digital signals that come from different buttons of the controller to the different levels of the analog signal, that can be transmitted through a single wire. In order to achieve that, we need a way to perform Digital to Analog conversion. We will construct a simple R-2R resistor ladder DAC for this matter. For the sake of simplicity lets assume we need to detect keypresses of the following buttons: D-pad (top, right, bottom, and left arrows), X key, O key; six buttons in total plus one additional signal level for the state of no buttons pressed. Minimal resolution of the DAC that will allow us to encode that many signal levels (namely seven) equals 3-bit. In theory that gives us the ability to encode as many as 8 different levels. So we got ourselves one spare here.

3-bit DAC

Low-pass RC filter

Sketch

Demultiplex

Sketch

Complete schematic and breadboard

Schematic

Breadboard

Run

Clone this wiki locally