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 » Can't upload

January 26, 2011
by Jalex
Jalex's Avatar

It compiles with no errors then I get an error that says can't find the file specified. I have checked and it looks like all the files are there and the Com port is right. The programs is your Tempsensor with some code at the bottom and a few changes to the LCD print out. I can paste it too if you need. I can also link the a copy of the dos screen if you need.

Here is a copy of me Makefile.

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 USB4
LINKOBJECTS=../libnerdkits/delay.o ../libnerdkits/lcd.o ../libnerdkits/uart.o

all:    MyNewTimer-upload

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

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

MyNewTimer-upload:  MyNewTimer.hex
    avrdude ${AVRDUDEFLAGS} -U flash:w:MyNewTimer.hex:a

( MyNewTimer.hex,all, MyNewTimer-upload,MyNewTimer.ass:)

Are in Red. Does this mean there is an error in these lines?

January 26, 2011
by Jalex
Jalex's Avatar

I have uploaded a few programs to the MCU without any trouble but I suspect I might have a bad USB on my comnputer because it doesn't always recognize my mp3 player.

January 26, 2011
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Jalex,

Please post the full error you get on the command line. It will help us narrow down what the problem might be.

Humberto

January 27, 2011
by Jalex
Jalex's Avatar

Hi [IMG]http://i55.tinypic.com/rjjgb6.jpg[/IMG]

Below is the Code. You will still recognize it as it's your Tempsensor code. At the bottom I added the pin selecting. I have comparitors that output a narrow pulse when an RC is charged and I want to count the time the pulse is high and print the number. The temp sensor is unchanged.

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

#define F_CPU 14745600

#include <stdio.h>
#include <math.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 -- temperature sensor analog input

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() {
  // read from ADC, waiting for conversion to finish
  // (assumes someone else asked for a conversion.)
  // 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);

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

  return result;
}

double sampleToFahrenheit(uint16_t sample) {
  // conversion ratio in DEGREES/STEP:
  // (5000 mV / 1024 steps) * (1 degree / 10mV)
  //    ^^^^^^^^^^^      ^^^^^^^^^^
  //     from ADC         from LM34
  return sample * (5000.0 / 1024.0 / 10.0);  
}

int main() {
  // start up the LCD
  lcd_init();
  FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_WRITE);
  lcd_home();

  // start up the Analog to Digital Converter
  adc_init();

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

  // MAKE PIN4  AN output
  DDRC |= (1<<PC4);
  // Make Pin1 pin2, and pin3 as an input
  DDRC &= ~(1<<PC1);
  DDRC &= ~(1<<PC2);
  DDRC &= ~(1<<PC3);
  DDRC &= ~(1<<PC5);
  // int Result as 16 bit 
  uint16_t Direct = 0;
  uint16_t Tc = 0;
  uint8_t WindCnt = 0;
  uint8_t Rain = 0;
  // holder variables for temperature data
  uint16_t last_sample = 0;
  double this_temp;
  double temp_avg;
  uint8_t i;

  while(1) {
    // take 100 samples and average them!
    temp_avg = 0.0;
    for(i=0; i<100; i++) {
      last_sample = adc_read();
      this_temp = sampleToFahrenheit(last_sample);

      // add this contribution to the average
      temp_avg = temp_avg + this_temp/100.0;
    }

    // Write Info to LCD

    lcd_home();
  fprintf_P(&lcd_stream, PSTR("Temperature: %.2f"), temp_avg);
  lcd_write_data(0xdf);
  lcd_write_string(PSTR("F      "));
  lcd_line_two();
  fprintf_P(&lcd_stream, PSTR("Degrees : %.3f"), Direct);
  lcd_line_three();
  fprintf_P(&lcd_stream, PSTR("Wind Speed : %.2f"), WindCnt);
  lcd_line_four();
  fprintf_P(&lcd_stream, PSTR("Inches Rain Fall: %.3f"), Rain);

    // write message to serial port
    printf_P(PSTR("%.2f degrees F\r\n"), temp_avg);

     // Get wind direction
        // Turn on PC4 
    //Result = 0;   
    PORTC |= (1<<PC4);
    delay_ms(5);
    //turn PC4 back off
    PORTC &= ~(1<<PC4);
    // Count to 180 only when PC5 is low

    while (PINC &= (1<<PC1) && ((Direct <180))) {
    delay_us(1);
    Direct++;
    }

     // If IR is on then add the difference to 180
    if (PINC &= (1<<PC5)) {
     Direct = ((180 - Direct)) + 180;
    }

    // Count Wind speed 
    WindCnt = 0;
    // Turn on PC4 
    PORTC |= (1<<PC4);
    delay_ms(5);
    //turn PC4 back off
    PORTC &= ~(1<<PC4);
   while (Tc < 300)  {
   while (PINC &= (1<<PC2) && ((WindCnt < 200)))  {
    delay_us(1);
     WindCnt++;
           }
         Tc++;
         }

       // Count Rain Fall
     Rain = 0;

    // Turn on PC4 
    PORTC |= (1<<PC4);
    delay_ms(5);
    //turn PC4 back off
    PORTC &= ~(1<<PC4);

    while (PINC &= (1<<PC3) && ((Rain < 60))) {
    delay_us(1); 
    Rain++;
       }

     delay_ms(1000);
     }

  return 0;
}
January 27, 2011
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Jalex,

The problem here is that the port you are using should read "COM4" not "usb4" (the number will change depending on where you plug it in or how many devices you have plugged in). Did you go through the NerdKits Guide and complete the projects there? If not I definitely recommend that you do.

Humberto

January 27, 2011
by Jalex
Jalex's Avatar

Thanks Humberto That was a dumb mistake. LOL I wrote USB3 instead of COM3 I did have a usb port problem on my other computer though and I guess that confused me. It works now. thank you for the help. Jim

January 27, 2011
by Jalex
Jalex's Avatar

Hi Again I do have one more question though. My display reads 000perature: 73.27 What is causing that? It works fine and icreases when I touch it like it should. Thanks Again.

January 27, 2011
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Jalex,

If your strings are running into each other it probably means you are overflowing one of the lines. Remember the lines of the LCD wrap around each other.

Humberto

January 27, 2011
by Jalex
Jalex's Avatar

Hi Humberto Ok Thanks I found that one, it was overwriting the beginning of the same line. Now I have another one. My counters only displayed 0's. I changed my uint16_t to Double and now they seem to work but is that right? Where did you say I could find a good c tutorial for the AVR?

Post a Reply

Please log in to post a reply.

Did you know that interrupts can cause problems if you're not careful about timing and memory access? Learn more...