NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Project Help and Ideas » Strain Gauge project problem

March 03, 2010
by vegardbr
vegardbr's Avatar

Hi, I got my NerdKit two days ago and its great.

Today I started the strain gauge project with 120ohm strain gauges and the AD620 amplifier. The program on the MCU seems to work fine, and get a 2volt signal back from the amplifier.

Now, the problem seems to be within the python interface. I have downloaded pygame and serial, but still there are problems running the program (in vista).

This is what is says:

Measuring zero... damn, got 2

damn, got 5

damn, got 278

damn, got 23

damn, got

damn, got 2

damn, got 2772

damn, got 2

damn, got 23

damn, got 2

....

It's this code that stops it:

def getReading(self):

x = self.s.readline()

k = x.split()

if len(k)<2:

  print "damn, got", x

  return self.getReading()

Can anyone tell me why or how I can fix my problem?

Thanks, Vegard

March 03, 2010
by mrobbins
(NerdKits Staff)

mrobbins's Avatar

Hi Vegard,

Have you tried looking at what's coming over the serial port using a serial terminal program such as Putty? See instructions here (scroll down to Serial Port Communicatoins).

We added that check because occasionally bad data might come over the serial port, and we wanted to prevent that bad data from disturbing the reading. With Putty, you should be able to see whether it is basically doing the right thing or not.

Mike

March 08, 2010
by vegardbr
vegardbr's Avatar

These are some putty values:

342 501

343 502

342 502

343 501

343 503

343 502

344 501

341 501

341 502

342 502

These values change, as they should, when the strain gauges are stretched. This leads me to believe that there is something wrong in the Python program. I have no experience with python, so I have just used the standard code, as downloaded from your site. Still it is strange that I seem to have two numbers? One at approximately 340 and one at 500.. the first increases and number two decreases.

Please comment what I could do differently,

Vegard

March 10, 2010
by vegardbr
vegardbr's Avatar

The string x is always suppose to be two numbers, of course.

It seem that there are some problems with receiving the signal from the micro-controller.

x: ... ...

x: 495 311

x: 562 266

x: 509 267

x: 530581 328336

x: 525 2

x: 587 312580 315

I have tried a modified version of the python-program in winVista and win7 32bit. On 4 different machines, but it always seems to mess up the reading after 460-470 readings.

-Vegard

March 11, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi vegarbr,

After it messes up, does it just stay off forever? It does not surprise me that you get a few readings off every once in a while. These systems are subject to noise and other uncertainties that could easily cause a reading to be off every once in a while. These irregular errors can just be detected and discarded on the PC software side.

If the whole thing goes off and you get nothing but errors, then I suggest slowing down the sending on the microcontroller side, see if that helps. It would help the quality of your readings if you averaged several readings (10 or so at a time should do it) together on the MCU side before sending them down the serial port. It will take a little bit of work on the code side, but I think it might solve your problem.

Humberto

March 11, 2010
by vegardbr
vegardbr's Avatar

Thank you Humberto. The last part of your post fits my description.

I guess this is probably a problem with the buffering of data. This is how my while-loop now looks like (and it works!(yay!), although its quite slow):

while(1) {
PORTD |= (1<<PD3);
PORTD &= ~(1<<PD4);
delay_us(66);
reading1 = adc_read();

PORTD |= (1<<PD4);
PORTD &= ~(1<<PD3);
delay_us(66);
reading2 = adc_read();
printf_P(PSTR("%d %d\r\n"),reading1,reading2);
delay_ms(20);

I will try what you said and post the code here.

Thanks, Vegard

Post a Reply

Please log in to post a reply.

Did you know that you can turn a $20 digital scale into a live weight sensor using our kit with a few extra parts? Learn more...