I’m trying to connect a Force sensing resistor to my Baby O. In this case I’m trying to control a LED to switch it on and off with the FSR. If the FSR is pushed for more the 2 seconds the LED should go on. If the FSR is pushed again for more then 2 seconds it should go off.
I’ve been trying this with the command “analog_read_average()” and the FSR connected to PC0, but I’m not shure if it’s reading anything. My “programming” so far has only resulted in continoues ON off the LED. It doesn’t seem to read the FSR at all.
Is there a way to print values of variables on the computer-screen?
Can somebody help me with the programming of this FSR?
I’m new to AVR’s and new to programming in C, so I’m learning as I go. Been looking through the Library Command Reference, the examples and so on and with that information trying to puzzle together my small baby-step tests to get familiar with my Baby O.
How do you have your FSR connected to the Baby O, and which FSR are you using? I suggest you start with a simpler program that just turns on the LED when the FSR output is above a certain voltage (don’t worry about this “on/off for two seconds” yet).
If you have our USB AVR programmer, you can use its USB-to-serial adapter to transmit data back and forth with your computer. Section 6 of the programmer’s user’s guide talks about how to use its serial-adapter, but to briefly summarize:
Connect the programmer’s TX pin to pin PD0 on the Baby Orangutan.
Connect the programmer’s RX pin to pin PD1 on the Baby Orangutan.
Connect the programmer’s ground pin to the Baby Orangutan’s ground.
You can then use the serial functions from the Pololu AVR library to send data from the Baby Orangutan to the computer through the programmer, and you can use a terminal program (e.g. hyperterm, teraterm, PuTTY, etc.) connected to the proper virtual COM port to display the information the Baby Orangutan is sending (and you can even use it to send information back to the Baby O).
You aren’t supplying power anywhere to the FSR. The FSR is just a resistor, so to get a meaningful output you need to put it into a voltage divider circuit. Can you try enabling the internal pull-up on PC0? When there is no force on the FSR, the internal pull-up should make the voltage close to 5 V on the pin. When there is a lot of force on the FSR, its resistance should drop to something much smaller than the internal pull-up, which should make the voltage on the pin get pretty close to 0 V. You can turn on PC0’s internal pull-up by calling:
You aren’t using the analog functions properly. The only function you need to call is analog_read_average(), and you should be calling it in your main loop:
delay(1); // give voltage on PC0 time to stabilize
set_analog_mode(MODE_8_BIT); // 8-bit analog-to-digital conversions
unsigned int sensorOutput = analog_read_average(0, 20);
if (sensorOutput < 127)
set_digital_output (IO_D1, HIGH); // drive PD1 high
set_digital_output (IO_D1, LOW); // drive PD1 low
This code should turn the PD1 LED on whenever you push hard enough on the FSR. You can test it very easily without the FSR by just touching a wire from PC0 to ground. Whenever you make the ground connection, the LED should turn on; otherwise, it should be off. Also, you might try using a multimeter to look at the voltage on the PC0 pin as you apply varying amounts of force to the FSR to see if it’s doing what you expect.
Thanks, that is working like a charm!
I measured the voltage drop on pin PC0 and the voltage drops quite quickly with a little pressure on the FSR. It drops so fast that I had to give the sensorOutput a value of “10”, to set the needed amount of pushing force applied on the FSR to a practical usable limit.
This is ok for my application, but I just thought I’d mention it because I was expecting a wider range…
You can get a wider range by using a stronger pull-up resistor. Instead of using the internal pull-up (you can find the value of this in the datasheet, but I think it’s between 30k and 60k), you can use a smaller external pull up resistor between PC0 and VCC. Maybe start with 10k and work your way down until you have the range you want.
If you want a more rigorous approach, you can decide what force you want to correspond to the middle of your range, and then measure the FSR resistance while applying this force. If you use a pull-up resistor close to this value, the FSR will output approximately Vcc/2 (5V on the Orangutan) when you apply that amount of force.
I too am doing this but thought the FSR was to be connected to PC0 and the other lead powered by onboard 5v VCC. I tested without the FSR by touching PC0 to VCC, and now it’s unresponsive and the voltage regulator gets hot. So now I’m confused how the FSR works the the B-328, and it’s time for a new B-328 I suppose.
Was I to just connect the FSR to PC0 and GND? I’m unsure because GND is 12v and “analog_read_average” responds within the range of 0-5V.
I apologize for the delayed response (you are certainly welcome to bump pending posts sooner!). The FSR acts like a resistor, and you read the force by reading the resistance. One way to do this is to put the FSR into a voltage divider circuit and look at the voltage output. My earlier post in this thread does that by enabling the internal pull-up resistor on PC0 (that becomes the top resistor of the voltage divider pair); the second resistor becomes the FSR, which connects between PC0 and ground. As you push on the FSR, the resistance goes down, and the output of the voltage divider shifts from VCC towards 0 V.
If you wanted a response from my example program, you should have touched that pin to ground to simulate a lot of force on the sensor, not to VCC. However, touching that pin to VCC should not have damaged anything if you were running my program (and, unfortunately, it certainly sounds like your Baby Orangutan is now damaged). I suspect you either touched VCC to something else (like ground), or you touched it to PC0 while it was a driving-low output.
You are either fundamentally misunderstanding something or doing something terribly wrong if your GND is at 12 V. Why do you say that?
Thanks Ben. It seems I have quite a learning curve ahead of me and I would like to inquire about instead hiring someone to create a program that serves several functions using FSRs and a DC gear motor with encoder. Where should I look to for this?