Show Posts
Pages: [1] 2
1  Using Arduino / Microcontrollers / Re: Reburn ATMega328 Bootloader from Uno to Internal Clock on: December 09, 2012, 07:36:20 pm
Hi Nick,

Just breadboarded the circuit.  Indeed, the external oscillator bootloader burns fine when I do it this way now that the fuses were reconfigured from the previous burn.  Guess there is a loose connection somewhere in my new shield.

Glad I could fix the issue though!  Thank you so much for your help!  Learned something new today  smiley.

I thought that the chip configured its fuses (i.e. clock/no clock) based on what was connected to it.  As such, I was under the impression that I needed to have a dedicated circuit for burning bootloaders with and without external clocks.  Good to know that I can use my old shield for both!  Still bugs me that the other shield isn't working, so I'll go hunt for the loose wire anyway smiley-wink.

Cheers!
arduinoRobo
2  Using Arduino / Microcontrollers / Re: Reburn ATMega328 Bootloader from Uno to Internal Clock on: December 09, 2012, 07:26:02 pm
Hi Nick,

Thank you for getting back to me so quickly.  I just tried what you suggested and the following happened:

I put the chip into the shield with the crystal, selected my board as an Atmega328 with an internal crystal, and clicked burn bootloader.  According to the Arduino environment, the bootloader burned successfully, which is great news.

However, I now wanted to verify that my new, dedicated shield (the one without the crystal), could also burn the bootloader.  Unfortunately, when trying to burn the bootloader with this shield, I get the "Device signature = 0x000000." error again.  Turning on verbose output, I get an avr dude message that says "AVR device initialized and ready to accept instructions," which would suggest to me that the chip is recognized and is ready to go.  However, the device signature error still makes it seem as if my chip is not responding.  I guess this means there is still an error in my protoshield circuit?

I will try breadboarding the internal crystal bootloader circuit to see if this works and report back.

Thanks!
Alex
3  Using Arduino / Microcontrollers / Re: Reburn ATMega328 Bootloader from Uno to Internal Clock on: December 09, 2012, 06:57:41 pm
Hi Nick,

Thank you very much for the links.  These are great references.  Reading the "Alternate Clock Source" section of your second post, I had a quick question.  From this text, am I correctly understanding that the chip in my current setup is not responding ( "Device signature = 0x000000." error) when in my new protoshield because there is no external clock?  Because the chip is expecting an external oscillator, but is not getting anything, nothing is "ticking" on the microcontroller, causing it to be unresponsive, correct?

As such, could I simply use my old protoshield (the one with a 16MhZ clock) to make the chip responsive, and, using the ArduinoISP sketch that comes with the Arduino programming environment, choose to burn the 8MhZ internal bootloader instead of the Uno bootloader when the chip is in this shield?  Would this successfully reset the fuses, or is the fuse resetting something unique to your Atmega board programming sketch?

Thanks again for the links!
arduinoRobo
4  Using Arduino / Microcontrollers / [SOLVED] Reburn ATMega328 Bootloader from Uno to Internal Clock on: December 09, 2012, 06:18:29 pm
Hi Everyone,

Apologies if a similar question has been posted before -- I searched around this section, but was not able to find an answer.

I recently purchased a blank Atmega328p for an embedded project.  To save components, I would like to have this Atmega328 use its internal clock.  Per the instructions here, I set up my Uno as an ISP, wired up a breadboard circuit, and was able to program my blank Atmega to use its internal clock.  Thinking I may use this bootloader variant for multiple future projects, I transferred my breadboard circuit onto a protoshield and tried to re-burn the bootloader to the chip.  The burn was not successful.  

I later realized that this burning instance failed, due to the fact that my male header pins weren't making contact with my Uno female headers.  However, before realizing this, I thought I may have fried my Atmega328, so, to verify the chip's functionality, I burned an Uno bootloader (w/ external oscillator) to the chip using a shield I previously made.  

The good news is that the Uno bootloader burned successfully, so the chip is not fried.  The bad news is that now that I've fixed the header issue on the new protoshield, I am unable to reburn the internal clock bootloader to the chip.  Instead, I get the dreaded "Device signature = 0x000000.  Yikes! Invalid device signature." error whenever I try to reburn the internal clock bootloader.    

After some searching online, I found a reference that suggest by burning the Uno bootloader, I set the chip's fuses to use an external oscillator and that this cannot be reset using an Arduino as an ISP.  Does this seem correct?  Could anyone offer insight into this for me?  Also, if anyone could offer some advice as to how to reset this Atmega chip without having to purchase an external programmer, I would appreciate it.

Thanks in advance!
arduinoRobo
5  Using Arduino / Programming Questions / Re: USBKeyboard.h occasionally hangs on: July 02, 2012, 09:17:31 pm
Hi Everyone,

I wanted to report back on this project.  Unfortunately, I am still having problems getting the circuit up and running.  As suggested, I have created both a breadboard version and a protoboard version, but the same problem persists in both cases.  I've checked the wiring on both versions and it seems to be correct.  As such, I am wondering if this issue is related to my choice of components...

Whenever I plug the circuit into USB, I receive an error that says "USB Device not recognized."  Per what I've found online, this issue seems to be related to the 2.2K pull-up resistor, which, when working, would cause the Arduino to be recognized as a low speed USB device.  I wanted to play around with different resistor types, so I ordered these 2.2K metal oxide resistors from Mouser.  I just noticed that they are rated for 2 watts. (The 68Ohm resistors are also metal oxide and rated for 2 watts.)  Could this higher power rating be causing my issue?  I ask because I know that the Zener diodes' power rating matter, since a Zener diode's capacitance goes up as the power rating increases.  However, I'm not sure if this is the same case with resistors -- shouldn't this rating just be related to how much power the resistors can take before they release their magic smoke?  Any insight from you guys would be greatly appreciated!

Other information -- I am running 64bit Windows 7 and I've tried plugging the circuit both into a USB 2.0 and USB 3.0 slot to no avail. 

Thanks again!
6  Using Arduino / Programming Questions / Re: USBKeyboard.h occasionally hangs on: June 20, 2012, 05:04:43 pm
Aha!  So that's the secret!   smiley

Thanks a lot for the information -- I haven't looked into the USB code yet, but this suggests to me that the Arduino must apparently wait for a "successful transmission" confirmation from the PC that the keystroke was sent before it exits out of the UsbKeyboard.sendKeyStroke() function and continues executing the code.  So, my arduino actually wasn't freezing, it was just never getting the response that it was looking for to continue.

This may also explain why committing to solder made things work out better for you.  You probably had a loose wire in there somewhere.

Thanks for your help, huntd69 and Nick!  Looks like I'll be placing a component order tonight  smiley-lol.

arduinoRobo
7  Using Arduino / Programming Questions / Re: USBKeyboard.h occasionally hangs on: June 20, 2012, 04:01:41 pm
Hi Nick,

Thanks for your help.  Please find my header definitions and setup() function code below:

EDIT: Didn't post the latest version of the code -- posted version did not have Serial.begin(9600); at the bottom of setup().

Code:
#include "UsbKeyboard.h"

// Define the inputs to use for buttons
#define BUTTON_A 6
#define BUTTON_B 7
#define BUTTON_C 8
#define BUTTON_D 9
#define BUTTON_MSG 10
#define BUTTON_ENTER 11

// Use the on-board LED as an activity display
int ledPin = 13;

/**
 * Configure button inputs and set up the USB connection to the host
 */
void setup()
{
  // Set up the activity display LED
  pinMode (ledPin, OUTPUT);
  digitalWrite (ledPin, HIGH);

  // Set the button pins to inputs
  pinMode (BUTTON_A, INPUT);
  pinMode (BUTTON_B, INPUT);
  pinMode (BUTTON_C, INPUT);
  pinMode (BUTTON_D, INPUT);
  pinMode (BUTTON_MSG, INPUT);
  pinMode (BUTTON_ENTER, INPUT);

  // Enable the CPU's internal 20k pull-up resistors on the button
  // inputs so they default to a "high" state
  digitalWrite (BUTTON_A, HIGH);
  digitalWrite (BUTTON_B, HIGH);
  digitalWrite (BUTTON_C, HIGH);
  digitalWrite (BUTTON_D, HIGH);
  digitalWrite (BUTTON_MSG, HIGH);
  digitalWrite (BUTTON_ENTER, HIGH);

  // Disable timer0 since it can mess with the USB timing. Note that
  // this means some functions such as delay() will no longer work.
  TIMSK0&=!(1<<TOIE0);

  // Clear interrupts while performing time-critical operations
  cli();

  // Force re-enumeration so the host will detect us
  usbDeviceDisconnect();
  delayMs(250);
  usbDeviceConnect();

  // Set interrupts again
  sei();

//Begin serial
Serial.begin(9600);
}

In my test setup, I'm trying to read pin 8, which is BUTTON_C.
8  Using Arduino / Programming Questions / Re: USBKeyboard.h occasionally hangs on: June 20, 2012, 03:48:16 pm
Hi huntd69,

Thanks for the advice.  Once I verify that the code works as it should, I will be moving everything onto a PCB.  I would like to use an embedded Arduino circuit I made in the eventual keyboard device.

At this point, however, I don't yet have any components to solder.  I literally just have a commercial Uno with a jumper connected to the input pin at one end, which I then manually plug into a GND pin on the Uno while the code is running.  My hope was that I could use this to verify that the button is reading (and thus the USB signals are sending) by looking at whether the LED on pin 13 goes off when the button is grounded out.  For some inexplicable reason however, it is freezes every time and as soon as it reads the button once -- since I get exactly one 0 printed out to the serial monitor before nothing else prints...?
9  Using Arduino / Programming Questions / Re: USBKeyboard.h occasionally hangs on: June 20, 2012, 02:08:39 pm
Hi Everyone,

I'm working on an identical project as huntd69.  I am hoping to use the VirtualUSBKeyboard sketch to make an Uno act as a USB keyboard.

Like huntd69, my arduino freezes whenever a button is pressed.

Prior to purchasing the USB circuit hardware from Mouser, I wanted to verify that I could get the code to behave correctly.  As such, I would like to have the Uno's LED on pin 13 turn off whenever I connect an input pin to the Uno's GND via a jumper.

Unfortunately, whenever I connect the input pin to GND, the Uno freezes.  To monitor what is happening, I added the following code at the top of void loop():

Code:
void loop()
{
  UsbKeyboard.update();
  Serial.println("New Loop");
  Serial.println(digitalRead(BUTTON_C));
...

This produces the following output:
Quote
New Loop
1
New Loop
1
New Loop
1
New Loop
0
From this output, it seems that the Uno is successfully reading that the input pin is connected to GND once, but then freezes.  I've tried multiple Unos, but all of them exhibit the same behavior.

Could you provide me with pointers to understand what is happening?

Thanks for your help!
arduinoRobo
10  Using Arduino / Sensors / Re: SSI Clock Signal for Rotary Encoder on: February 18, 2012, 04:29:42 pm
Hi Guys,

Thanks to MarkT, my code is getting better and better.  Here is my code for creating/testing a clock for your reference.  I am using pins 2 and 3 to read the data.  The only issue now is that I am sometimes receiving numbers other than 3 and 15, depending on the state of Rx and Tx.  However, it should work fine when connecting it directly to an SSI device to use as a clock.  For consistent output, maybe I can use a bit mask?  Excited!   smiley-mr-green

Code:
/* Arduino Port Manipulation to Generate Clock Signal
 * 02/18/2012 
*/

/*Please see the "Port Manipulation" article here: http://www.arduino.cc/playground/Learning/PortManipulation
   *NOTE: The ATmega328 (used on the UNO) has an identical pin configuration to the ATmega168 (described in the Port Manipulation documentation). http://arduino.cc/en/Main/arduinoBoardUno
   *ATmega328 has three ports: D - Digital Pins 0-7, B - Digital Pins 8-13, C - Analog Pins 0-5
   *For safety, do not use:
   *Port D - Pins 0 & 1 are used for serial communications for programming and bebugging the Arduino.  This can mess up the chip's send and receive.
   *
   *DDR is the direction register and sets whether the port is input or output
   *To set input/output use DDR<LETTER> - 0 is input, 1 is output
   *Alternatively, since it is only run once during setup(), it is satisfactory to use pinMode(pinNumber, OUTPUT);
   *
   *PORT is the register for the state of the outputs.  It sets whether the value of an output pin is high (1) or low (0)
   *To set state of a specific pin on the Arduino UNO, use PORT<LETTER><PIN_NUMBER>
   *
   *PIN is the input register variable.  It will read all of the digital input pins at the same time
   *To read the pins on a specific port use PIN<Letter>
   *   
*/

 int DATA_MINUS_PIN = 2; //Pin for reading minus signal
 int DATA_PLUS_PIN = 3; //Pin for reading plus signal
 
 int CLOCK_MINUS_PIN = 11; //Pin for clock minus signal
 int CLOCK_PLUS_PIN = 12; //Pin for clock plus signal
 
 void setup()
 {
   pinMode(CLOCK_MINUS_PIN, OUTPUT); //Set clock minus pin as output
   pinMode(CLOCK_PLUS_PIN, OUTPUT); //Set clock plus pin as output
   
   pinMode(DATA_MINUS_PIN, INPUT); //Set data minus pin as input
   pinMode(DATA_PLUS_PIN, INPUT); //Set data plus pin as input
   
   delay(500);
   Serial.begin(115200); //Set serial baud rate
 }
 
 void loop()
 {
  PORTB = B00011000; //Set Port B pins 11,12 HIGH, others LOW
  Serial.println(PIND); //Read all Port D pins (0-7) simultaneously and print
  delayMicroseconds(10); //Delay for 10 microseconds for timing
  PORTB = B00000000; //Set all Port B pins LOW
  Serial.println(PIND); //Read all Port D pins (0-7) simultaneously and print
 }

Now on to reading and decoding the grey code from the encoder.  Hopefully I will have something soon.

Thanks again!
arduinoRobo
11  Using Arduino / Sensors / Re: SSI Clock Signal for Rotary Encoder on: February 18, 2012, 04:04:06 pm
Sorry MarkT!

As I was typing my latest post, I saw that you responded before I could finish my own reply!  smiley-grin  Man you are fast!  Thank you so much for your help smiley-grin 

Indeed, you are correct, I forgot to set the pinMode.  This result led to the new questions/observations above. smiley
12  Using Arduino / Sensors / Re: SSI Clock Signal for Rotary Encoder on: February 18, 2012, 04:02:41 pm
EDIT: Didn't see MarkT had already posted the answer to the top half of this post while I was writing it.

Reexamining my code, I thought that a possible error may have come from the fact that I never set my pin data directions.

As such, I changed my setup() method to:

Code:

  void setup()
 {
   DDRB = (1<<PORTB4); //PORTB4 is digital pin No 12 -- OUTPUT
   DDRB = (1<<PORTB3); //PORTB3 is digital pin No 11 -- OUTPUT
   DDRD = (0<<PORTB2);
   DDRD = (0<<PORTB3);
  delay(500);
  Serial.begin(115200);
 }


Now I am getting 15s and 3s in my Serial output, where the 3 is sometimes replaced by an 11 or a 1.

This suggests the following binary numbers:

B00000001 = 1
B00000011 = 3
B00001011 = 11
B00001111 = 15

Therefore, both input ports are now changing, the mistake being that I did not set them for reading.

Looks like I am getting closer, which is exciting!  This is fun!  smiley-mr-green

This output leads me to 4 more questions:

1.) Unfortunately, since I am turning both pins on and off simultaneously, I would never expect to receive an 11 in my Serial output... does anyone know what could be causing this?  

2.) Is there a way to only read from only two pins simultaneously, instead of reading from all pins on a port?

3.) From this example code, I found that it is possible to set individual DDRB values using the "<<" operator.  But from the BitMath documentation, I see that << is a bit shift.  Why can I not use = instead?

4.) As I wrote above, I still don't understand the changing Rx and Tx values.  If someone could explain this to me, I would appreciate it smiley.

Thank you again!
arduinoRobo
13  Using Arduino / Sensors / Re: SSI Clock Signal for Rotary Encoder on: February 18, 2012, 03:36:03 pm
After working my way through the port manipulation article more carefully, I think that I have implemented a clock, but am getting some strange results. 

Via my code below, I want to simultaneously set pins 12 and 11 HIGH, delay 10 microseconds (100kHZ), and then set pins 12 and 11 LOW. 

After each "set" operation, I am using pins 3 and 2 to read the value of PORTB using PIND, and printing the resulting number to serial.

Given the ports of PIND I connected the jumpers to, I would expect PIND to read the following binary numbers during each iteration:

B00000000
B00001100

which would be printed as

0 and 12 via Serial.println(), respectively. 

However, examining my serial output stream, I instead get alternating 15s and 7s, where the 15 is sometimes replaced by a 13.

This would suggest that PIND is reading the following binary numbers:

 7 = B00000111;
15 = B00001111;
13 = B00001101;

These results are strange to me, because this suggests that the value of pin 2 is never changing, since it is constantly 1...  smiley-confuse 

The two most far-right 1s and 0s of PIND are RX & TX from the documentation.  Given this, I can understand why I would not get 0 and 12, as these would be set to 0 and 1 for send/receive.  However, I do not understand why Rx would ever be set to 1 as this is input... since I am not sending code, I would not expect it to ever receive anything.  Conversely, I do not understand why Tx would ever be 0, as it should always be sending..?

I imagine I am still doing something incorrectly.  Am I interpreting the binary wrong?  Could someone please point me in the right direction? smiley

For your reference, my code is:

Code:
/* Arduino Port Manipulation to Generate Clock
 */
 
   void setup()
 {
   Serial.begin(115200); //Set serial baud rate
 }
 
 void loop()
 {
  PORTB = B00011000; //Set Port B pins 11,12 HIGH, others LOW
  Serial.println(PIND); //Read all Port D pins (0-7) simultaneously and print
  delayMicroseconds(10); //Delay for 10 microseconds for timing
  PORTB = B00000000; //Set all Port B pins LOW
  Serial.println(PIND); //Read all Port D pins (0-7) simultaneously and print
 }

EDIT: Alternatively, is there a way to simply read from 2 pins instead of all of PIND, but do so simultaneously?  This would eliminate the ambiguity with what Px and TX may be doing.  Still doesn't explain why pin 2 is always 1, though.

Thank you again for your help!
arduinoRobo
14  Using Arduino / Sensors / Re: SSI Clock Signal for Rotary Encoder on: February 18, 2012, 11:13:23 am
Hi MarkT,

Thank you for getting back to me so quickly.  I now have a better understanding of what is meant by "ports" and the port manipulation article makes more sense to me now. 

I will give this a shot and post my results!

Thanks again,
arduinoRobo
15  Topics / Robotics / Re: Arduino C-code implementation of velocity detection??? on: February 18, 2012, 10:44:35 am
Hi Ken,

By "closing speed" I assume you mean that you want to measure how quickly the car is approaching the wall and adjust its velocity proportionally, (no wall = full speed, approaching wall = slower and slower speed), correct? 

You could estimate the car's velocity by calculating the difference between subsequent sensor readings (or an average of multiple subsequent readings b/c of sensor noise) and dividing it by the time between readings.  Essentially, you are finding the numerical derivative of your position indicated by the sonar sensor readings.  Then, you could increase or decrease the current to the car's motors based on how close you are to the wall. 

To get the time between readings, try using the Time library, or more directly the now() function.  Not sure what the resolution of the time is -- might only give you integer seconds as opposed to fractions of a second via a double or float, but it's worth a shot! smiley

arduinoRobo
Pages: [1] 2