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.

Support Forum » Weight Scale Load cell Makefile Help

November 29, 2012
by gasrcboat
gasrcboat's Avatar

I cannot seem to create the proper make file. I am using the temp sensor make file. How do I combine the tutorial weight scale file with the temp sensor file? Any help would be greatly appreciated! Thanks, n00b

November 29, 2012
by Ralphxyz
Ralphxyz's Avatar

How do I combine the tutorial weight scale file with the temp sensor file?

Is this your actual question or do you have a program file (weight scale + temp sensor) that you need to MAKE?

Ralph

November 29, 2012
by sask55
sask55's Avatar

As Ralph has said, fundamentally the make file is a bit of code used to compile a C code program file and write that set of instructions onto the Microprocessor chip. For a beginner the make file will not change from one project to the next except for the name of the C code program file that you want to install on the Micro.

Are you attempting to MAKE the weight scale program file “weightscale.c” found in the weight scale project?

Or

Are you attempting to MAKE the tempsensor program file “tempsensor.c” found in the tempsensor project?

Or

Are you are attempting to MAKE a project that is some kind of combination of the temp sensor and the weight scale projects?

To do this you will have to write c code instructions to do what you have in mind. You might base your new C code program file on weightscale.c, or on tempsensor.c . By studying those two files, the weight scale tutorial and the Nerdkit guild you will get an understanding of what is require to write a set of C code instructions that will carry out whatever you are attempting to do. Once you have written your C code that you think will produce the results you are looking for you then use a make file to compile your code and write it to the microprocessor chip.

I don’t think we understand what it is you are asking.

November 30, 2012
by gasrcboat
gasrcboat's Avatar

Thank you for your help. I am trying to create the weight scale project. I went way to deep into what was involved in the make file. The more I read on the make file for the project the further away I got. For some reason I thought I had to combine the source code for the weight scale and a Make file instead of just referencing it. I have Python running and the scale built, I will install the code and reference the make file as soon as I get a free moment. Thanks to all for the help.

November 30, 2012
by sask55
sask55's Avatar

One more point to consider.

The location, on the computer, of the C code program (source) file and the make file are important. The make file and the program file will both reference other files on your hard drive. In the make files supplied in the Nerdkit, there are 14 references to the source code .c file to be complied. All 14 should match the name of the source code .c file program file that in the same folder as that make file. The libnerdkits folder must be in the same folder as the folder containing both of those files.

If your relative file locations are correct and the make file is referencing the .c code sources code file in the same folder everything should work fine.

November 30, 2012
by gasrcboat
gasrcboat's Avatar

Back again and I feel really defeated! copy of makefile for weightscale.

GCCFLAGS=-g -Os -Wall -mmcu=atmega168 
LINKFLAGS=-Wl,-u,vfprintf -lprintf_flt -Wl,-u,vfscanf -lscanf_flt -lm
AVRDUDEFLAGS=-c avr109 -p m168 -b 115200 -P com1
LINKOBJECTS=../libnerdkits/delay.o ../libnerdkits/lcd.o ../libnerdkits/uart.o

all:    Weightscale-upload

Weightscale.hex:    Weightscale.c
    make -C ../libnerdkits
    avr-gcc ${GCCFLAGS} ${LINKFLAGS} -o Weightscale.o Weightscale.c ${LINKOBJECTS}
    avr-objcopy -j .text -O ihex Weightscale.o Weighscale.hex

Weightscale.ass:    Weightscale.hex
    avr-objdump -S -d Weightscale.o > Weightscale.ass

Weightscale-upload: Weightscale.hex
    avrdude ${AVRDUDEFLAGS} -U flash:w:Weightscale.hex:a
I get

Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\Dee\Downloads\Code\Code\Weightscale>make
make -C ../libnerdkits
make[1]: Entering directory `C:/Users/Dee/Downloads/Code/Code/libnerdkits'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `C:/Users/Dee/Downloads/Code/Code/libnerdkits'
avr-gcc -g -Os -Wall -mmcu=atmega168  -Wl,-u,vfprintf -lprintf_flt -Wl,-u,vfscan
f -lscanf_flt -lm -o Weightscale.o Weightscale.c ../libnerdkits/delay.o ../libne
rdkits/lcd.o ../libnerdkits/uart.o
Weightscale.c: In function 'main':
Weightscale.c:96: error: expected declaration or statement at end of input
Weightscale.c:71: warning: unused variable 'reading'
make: *** [Weightscale.hex] Error 1

C:UsersDeeDownloadsCodeCodeWeightscale> Thank you in advance.

November 30, 2012
by pcbolt
pcbolt's Avatar

@ gasrcboat

The error doesn't appear to be caused by a bad Makefile, it looks like the error is in the "compiling of the program" step. The error on line 10 above...

Weightscale.c:96: error: expected declaration or statement at end of input

... usually means a missing comma, semi-colon, or parenthesis etc in the source code file "weightscale.c". Check through that file to see if anything jumps out as being wrong. (You can ignore the warning unused variable message for now). When I tried the first time to download the code it came through all mashed together so if I tried to compile it I would have gotten errors. I saved it as a file directly the second time and it looked OK when I viewed it. If all else fails, see if you can post the code you are using, maybe someone here can spot something out of place.

November 30, 2012
by gasrcboat
gasrcboat's Avatar

This is my weightscale file.

// weighscale.c
// for NerdKits with ATmega168
// mrobbins@mit.edu

#define F_CPU 14745600

#include <stdio.h>

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <inttypes.h>

#include "../libnerdkits/delay.h"
#include "../libnerdkits/lcd.h"
#include "../libnerdkits/uart.h"

// PIN DEFINITIONS:
// PC0 -- analog in
//
// PD4 - bridge excite
// PD3 - bridge excite

void adc_init() {
  // set analog to digital converter
  // for external reference (5v), single ended input ADC0
  ADMUX = 0;

  // set analog to digital converter
  // to be enabled, with a clock prescale of 1/128
  // so that the ADC clock runs at 115.2kHz.
  ADCSRA = (1<<ADEN) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0);

  // fire a conversion just to get the ADC warmed up
  ADCSRA |= (1<<ADSC);
}

uint16_t adc_read() {
  // set ADSC bit to get the *next* conversion started
  ADCSRA |= (1<<ADSC);

  // read from ADC, waiting for conversion to finish
  // wait for it to be cleared
  while(ADCSRA & (1<<ADSC)) {
    // do nothing... just hold your breath.
  }
  // bit is cleared, so we have a result.

  // read from the ADCL/ADCH registers, and combine the result
  // Note: ADCL must be read first (datasheet pp. 259)
  uint16_t result = ADCL;
  uint16_t temp = ADCH;
  result = result + (temp<<8);

  return result;
}

int main() {
  // set PD3, PD4 as outputs
  DDRD |= (1<<PD3) | (1<<PD4);

  // init ADC
  adc_init();

  // init serial port
  uart_init();
  FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
  stdin = stdout = &uart_stream;

  int16_t reading;
  while(1) {
    // set polarity +-
    PORTD |= (1<<PD3);
    PORTD &= ~(1<<PD4);
    // wait 5 time constants (bw=12kHz, T=13.2us)
    delay_us(66);
    // take reading
    //reading = adc_read();
    printf_P(PSTR("%d "), adc_read());

    // set polarity -+
    PORTD |= (1<<PD4);
    PORTD &= ~(1<<PD3);
    // wait 5 time constants (bw=12kHz, T=13.2us)
    delay_us(66);
    // take reading
    //reading = reading - adc_read();
    printf_P(PSTR("%d\r\n"), adc_read());

    // send over serial port
    //printf_P(PSTR("%d\r\n"), reading);
  }

  return 0;
November 30, 2012
by pcbolt
pcbolt's Avatar

Ah. Looks like you are missing a closing brace after

return 0;

The one before it closes "while(1){" so you need one to close "main(){". So the final three lines should be

  }           // OK as is
return 0;     // OK as is
}             // This need to be added

Also, if you want to get rid of the warning message, just comment out (or get rid of) line 70 above.

November 30, 2012
by gasrcboat
gasrcboat's Avatar

I redid the source file and now I still get error 1

C:\Users\Dee\Downloads\Code\Code\Weightscale>make
make -C ../libnerdkits
make[1]: Entering directory `C:/Users/Dee/Downloads/Code/Code/libnerdkits'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `C:/Users/Dee/Downloads/Code/Code/libnerdkits'
avr-gcc -g -Os -Wall -mmcu=atmega168  -Wl,-u,vfprintf -lprintf_flt -Wl,-u,vfscan
f -lscanf_flt -lm -o Weightscale.o Weightscale.c ../libnerdkits/delay.o ../libne
rdkits/lcd.o ../libnerdkits/uart.o
Weightscale.c: In function 'main':
Weightscale.c:71: warning: unused variable 'reading'
avr-objcopy -j .text -O ihex Weightscale.o Weighscale.hex
avrdude -c avr109 -p m168 -b 115200 -P com1 -U flash:w:Weightscale.hex:a

Connecting to programmer: .
Found programmer: Id = "FDL v02"; type = S
    Software Version = 0.2; No Hardware Version given.
Programmer supports auto addr increment.
Programmer supports buffered memory access with buffersize=128 bytes.

Programmer supports the following devices:
    Device code: 0x35

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e9406
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed

         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "Weightscale.hex"
avrdude: error opening Weightscale.hex: No such file or directory
avrdude: input file Weightscale.hex auto detected as invalid format
avrdude: can't open input file Weightscale.hex: No such file or directory
avrdude: write to file 'Weightscale.hex' failed

avrdude done.  Thank you.

make: *** [Weightscale-upload] Error 1

C:\Users\Dee\Downloads\Code\Code\Weightscale>
November 30, 2012
by pcbolt
pcbolt's Avatar

@ gasrcboat -

Prepare for an "Arrrrrgh" moment...in your Makefile from 3 posts ago, you have this at line 11...

avr-objcopy -j .text -O ihex Weightscale.o Weighscale.hex

See the problem? "Weighscale.hex". No 't'.

November 30, 2012
by gasrcboat
gasrcboat's Avatar

Imagine that! Thak you, mcu flashed fine!

November 30, 2012
by Ralphxyz
Ralphxyz's Avatar

re: the missing t in the make file

This is where the:

ProgramName = initialload

all:    $(ProgramName)-upload

$(ProgramName).hex: $(ProgramName).c
    make -C ../libnerdkits
    avr-gcc ${GCCFLAGS} ${LINKFLAGS} -o $(ProgramName).o $(ProgramName).c ${LINKOBJECTS}
    avr-objcopy -j .text -O ihex $(ProgramName).o $(ProgramName).hex

$(ProgramName).ass: $(ProgramName).hex
    avr-objdump -S -d $(ProgramName).o > $(ProgramName).ass

$(ProgramName)-upload:  $(ProgramName).hex
    avrdude ${AVRDUDEFLAGS} -U flash:w:$(ProgramName).hex:a

Programname or Target or whatever works nicely to avoid this kind of problem!!

This is courtesy of bretm.

Ralph

Post a Reply

Please log in to post a reply.

Did you know that many systems in nature can be described by a first order response? Learn more...