Return of the AddaSlide

Okay, it’s been a while. But I promised layouts and schematics. First the schematics!AddaSlideSchematic

I know, simple right? P1 is the Gadgeteer connector, U1 is our handy dandy AtoD, and R1 is our slider. The rest is less important, some bypass caps to reduce noise in the system ( C2 and C3 ) another cap to reduce noise in our slider (C1) and we sprung for the fancy slider with an LED to light our way so we put a resistor nearby to stop it from burning out in a flash of glory.

Onto the layout!

Yeah… It’s kind of simple too. For those not familiar with layout layers. The red is the top copper layer, blue is bottom copper, and the yellow is the top silkscreen. And all the round guys are either mounting holes or vias.

Onward to more fun. The Code! I went over the flow of the driver last time, so go take a look if you forgot. There are only two fuctions, the constructor ( thats the one called when the driver is first created and sets up all the pins for inputs or outputs ) the other is the one you will use to get the position of the slider. Instead of returning the actual value read by the AtoD ( an integer between 0 and 255 ) I convert it to a float between 0.0 and 1.0.

I see you are getting impatient… Fine. Here you go. Wow, the formatting sucks. So you get an image of the code. Anyway, we could have made it a little cleaner with a couple of loops on the reads and writes, but the code that ends up on the Gadgeteer is virtually the same.

Just for fun, check out all these sliders we can use :)

Until Next time!


Developing a Gadgeteer Module: AddaSlider

I’m going to start off with a pretty simple module, a linear potentiometer ( a slider) hooked up to an ‘A’ socket. For those that dont know, the ‘A’ socket is an anolog input. ( you can learn about all of the sockets here ) To get useful information out of a slider you connect one end of the slide to ground ( pin 10 on gadgeteer connectors ), and the other end to 3v3 (pin 1), now as you move the slider from one end to the other, the wiper terminal will have a voltage between 0 and 3.3v. Connect this to analog input 1( pin 3 ) and you have an analog slide module.

That is great and all but there are two problems with this module.

  1. We have used an entire ‘A’ socket for one input ( there are 3 inputs available on an ‘A’ socket).
  2. We can only plug it into ‘A’ sockets and most mainboards only have one or two available.

We can resolve the first issue by adding 2 more sliders hooked up to the other two analog inputs on the socket. But the second issue is a little more difficult. We could add a microcontroller and make our module Daisylink compatible, that way we could chain several sliders off the same port. But this is our first module so lets try and keep it simple. So instead lets use an X or Y. I prefer to use X and Y sockets whenever possible, since most mainboards have several connectors that support either X or Y socket types. For instance GHI’s FEZ Spider has 2 Xs and 7 Ys. Now we have a new problem, these ports only support digital inputs. To overcome this we are going to use an ADC, its just like the one inside the CPU on the mainboard. I have a bunch of AD7468s laying around so lets use one here, it is 8bit and has a SPI interface. What does this mean? It means we get a number between 0 and 255 from it and we can use 3 GPIO pins to talk to it. This type of device is handy because it will talk as slow as you want or as fast as you want ( up to 200k samples per second) and does not require any crystals or CPUs to make it work. It’s as simple as supply power, enable it, supply a clock signal, and read the values. Okay, how do I do that? Well I’m gonna tell you, just hold on a second. If you looked through the datasheet you would see that our ADC has 6 pins:

  1. Power (3.3v from gadgeteer socket pin 1)
  2. Ground ( pin10 of socket )
  3. Vin – this is where our slider’s middle terminal is connected
  4. Sclk – we connect this on to an output pin of the gadgeteer socket, I randomly choose pin5
  5. Sdata – this is the ouput of the chip, I’ll stick this one on pin 4
  6. CS – this is the enable line, lets put it on socket pin3

I put our 3 IO lines on pins 3-5 so that our module will be compatible with either an X or Y socket, if we had more than 3 lines in our interface we could not use the X sockets. Since we are working on the module here I will not going into the specifics of writing the software but I will explain the steps of reading the value from the ADC. Even though the chip supports SPI we are not using a port that supports it, instead we are manually talking to it. Here are the steps:

  1. set CS low to enable the chip
  2. set Sclk low then back high again 3 times.
  3. set Sclk low then back high again.
  4. read value of Sdata
  5. repeat steps 3 and 4, seven more times.

Thats all there is to it. Now I must mention that by handling the communications manually we will be taking up a lot of time on the processor (~5ms on the FEZ Spider) but in the grand scheme of things I think the benefits of having an analog input that we can plug in almost anywhere outweighs the loss off a few clock cycles.

Next time I’ll show off the schematics and the board layout.