I just built the $50 robot, but I'm using the 4AA battery pack, isp mkII programmer, and the atmega328p. I haven't modified my servos yet, and I wanted to make sure my electronics was correct before doing that. I wanted to just successfully connect the programmer to the mcu, and program it. I wrote a simple program, which included SoR_Utils.h and just turned on the LED. The program compiled just fine. I connected the mkII to my pc. It downloaded the drivers successfully. I connected the mkII to my circuit, and plugged in the 9V battery. The LED on the programmer turned green. I programmed my LED_on hex file onto the mcu. No errors occurred, but my LED did not turn on. I tried unplugging the 9V, and plugging it back in. I also tried changing the program, recompiling, and programming again. I figured my LED might be bad or something, so I decided to plug in the servos, and try them out. I wrote a simple program which called servoleft() and servoright(). I programmed the mcu with that hex file, and the servos just buzzed. I rewrote the program several times. If I only called on one servo, only that servo buzzed. I had expected the servo to rotate to a specific angle, but neither servo ever moved. OK, HERE'S WHERE I REALLY REALLY SCREWED UP. (please know that I did not have access to internet as I was attempting this) I thought that maybe the mcu was running at the wrong frequency, so I ENTERED THE PROJECT CONFIGURATION OPTIONS and towards the bottom of the page with the option to use an external makefile, I CHANGED THE BLANK FREQUENCY BOX TO 8000000 Hz. I compiled the project, and as soon as I clicked the button to program my mcu, the LED in the programmer started blinking orange and I was no longer able to connect to my mcu. I unplugged the 9V, unplugged the programmer from my pc and my microcontroller, and even restarted my pc. Still, I am no longer able to connect my programmer to my mcu. As soon as I plug it in, the light blinks orange. Troubleshooting only told me that the voltage may be incorrect or the programmer may be plugged in backwards. I checked the voltage. It is still correct. My 9V has not died or anything, and I know that the wiring is correct because the programming was successful several times. Did I fry something? Do I need to reset a fuse or something? Please help me. Also, if anyone can tell me why my LED or servos were not working, please let me know. This was my source code:
#include "SoR_Utils.h"
int main(void){
configure_ports();
LED_on();
while(1){
}
return 0;
}
Also, my first attempt did not include configure_ports();
The code compiled just fine, and I WAS able to program my mcu with the hex file, but the LED never came on.
Here's my altered version of the Photovore_v1.c with which I was trying to make the servos rotate to, well, just anywhere. Last night was the first time I programmed an MCU, ever. I am an intermediate C++ programmer. This is my first attempt using C, as I understand avr has much more c support.
//SoR Include
#include "SoR_Utils.h" //includes all the technical stuff
int main(void)
{
//declare variables here
//int i=250;//a 'whatever' variable
int sensor_left=0;//left photoresistor
int sensor_right=0;//right photoresistor
int threshold=8;//the larger this number, the more likely your robot will drive straight
/****************INITIALIZATIONS*******************/
//other stuff Im experimenting with for SoR
//uartInit(); // initialize the UART (serial port)
//uartSetBaudRate(9600);// set the baud rate of the UART for our debug/reporting output
//rprintfInit(uartSendByte);// initialize rprintf system
//timerInit(); // initialize the timer system
configure_ports(); // configure which ports are analog, digital, etc.
//a2dInit(); // initialize analog to digital converter (ADC)
//a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling
//a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage
//rprintf("Initialization Complete\r\n");
/**************************************************/
/*********ADD YOUR CODE BELOW THIS LINE **********/
LED_on();//turn LED on
while(1)
{
//store sensor data
//sensor_left=a2dConvert8bit(5);
//sensor_right=a2dConvert8bit(4);
//detects more light on left side of robot
if(1==1)
{//go left
servo_left(35);
servo_right(35);
}
//detects more light on right side of robot
/*else if(sensor_right > sensor_left && (sensor_right - sensor_left) > threshold)
{//go right
servo_left(25);
servo_right(25);
}
//light is about equal on both sides
else
{//go straight
servo_left(25);
servo_right(44);
}
*/
/* Servo Test Code
i=250;
while(i>0)
{
servo_left(40);
i--;
}
i=250;
while(i>0)
{
servo_left(24);
i--;
}
*/
//rprintf("Initialization Complete\r\n");
//output message to serial (use hyperterminal)
//print("Hello, World! Read My Analog: %u\r\n", sensor_0);
delay_cycles(500);//a small delay to prevent crazy oscillations
}
/*********ADD YOUR CODE ABOVE THIS LINE **********/
return 0;
}