Show Posts
|
|
Pages: [1] 2
|
|
3
|
Using Arduino / Programming Questions / SoftwareSerial (on ATtiny85 8 MHz core) printing "boxes" - Answered
|
on: January 29, 2013, 09:35:51 pm
|
Hello, I've been trying unsuccessfully to get SoftwareSerial to display test characters to the IDE serial display. I have an ATtiny85 hooked up to a sparkfun FT232RL USB to Serial breakout board. I've been trying to run this program (modified SoftwareSerial example code): #include <SoftwareSerial.h>
SoftwareSerial mySerial(4, 3); // RX, TX int counter = 0;
void setup() {
// set the data rate for the SoftwareSerial port mySerial.begin(4800); mySerial.println("Hello, world?"); }
void loop() // run over and over { delay(100); mySerial.print("counter: "); mySerial.println(counter); }
And all I get are "boxes", [][][][][][] (if they were actually boxes) displaying to the Arduino IDE. It doesn't seem to matter whether I print an integer or a String, the only thing that happens is if I make the output: "11111111111111" vs "11111111" I get more or less "boxes." I've altered the baud rate both in the script and on the Serial monitor and it does change to garbled text if the code and the Serial monitor baud rates do not match up. I need it to work at 8 MHz as I believe that is what SoftwareSerial works at and 4800 baud is what my RF chip works at that I ultimately want to hook up to my circuit. Has anyone seen this before, any help? I'd very much appreciate help, my head hurts from all of the banging.  -Tweed
|
|
|
|
|
4
|
Using Arduino / Microcontrollers / Re: Solution to PCREL error for avr25.
|
on: January 10, 2013, 10:28:58 pm
|
Thanks for this, it always astounds me when I'm having problems with Arduino/AVR related issues, I can cut and paste something like: :/program files/arduino- .0.1/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o:(.init9+0x2): relocation truncated to fit: R_AVR_13_PCREL against symbol `exit' defined in .fini9 section in c:/program files/arduino-1.0.1/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/avr25\libgcc.a(_exit.o) Into google and find an answer. Thanks much. -tweedius
|
|
|
|
|
6
|
Using Arduino / Programming Questions / Local vs Global Var problem
|
on: May 29, 2012, 10:45:57 pm
|
Hello, I've been toying around with this code obviously getting different sensors, a joystick and an LCD working and all playing nice together which is why some of it is commented out currently. The main block of code works properly and does not crash. However when I move the variable block of code into the loop function I get random crashes and the output to my LCD locks up and I have to restart the arduino (mega 2560). Any clue as to why? I have a couple of other things I can do to the code to tidy it up, my whole reason for this post is to ask why it works to just define the variables once in the global section of code but I get some hangs when I put it in the loop. Is putting it in the loop a bad idea to begin with? Should I just be making functions to get this information for me and have it be returned to a working variable? Any help would be awesome and thank you! -Tweed Variable block of code:String range; String a_x, a_y, a_z; int x, y, z; int joystick_x, joystick_y; String j_x, j_y;
Main code:#include "ulcd_144.h" #include <Wire.h> #include <ADXL345.h>
#define RANGE_FINDER_PIN A0
#define JOYSTICK_HORZ_PIN A8 #define JOYSTICK_VERT_PIN A9
ADXL345 adxl;
String range; String a_x, a_y, a_z; int x, y, z; int joystick_x, joystick_y; String j_x, j_y;
void setup() {
Serial2.begin(115200); //set up serial port for lcd delay(500); //this delay is necessary to let the LCD start up init_lcd(); //initialize lcd init_motor_driver(); //initialize motor driver pinMode(RANGE_FINDER_PIN, INPUT); pinMode(JOYSTICK_HORZ_PIN, INPUT); pinMode(JOYSTICK_VERT_PIN, INPUT); /* //accelerometer setup code adxl.powerOn(); adxl.setActivityThreshold(75); adxl.setInactivityThreshold(75); adxl.setTimeInactivity(10); adxl.setActivityX(1); adxl.setActivityY(1); adxl.setActivityZ(1); adxl.setTapDetectionOnX(0); adxl.setTapDetectionOnY(0); adxl.setTapDetectionOnZ(0); adxl.setTapThreshold(50); adxl.setTapDuration(15); adxl.setDoubleTapLatency(80); adxl.setDoubleTapWindow(200); adxl.setFreeFallThreshold(7); adxl.setFreeFallDuration(45); //adxl.setInterruptMapping( ADXL345_INT_SINGLE_TAP_BIT, ADXL345_INT1_PIN ); //adxl.setInterruptMapping( ADXL345_INT_DOUBLE_TAP_BIT, ADXL345_INT1_PIN ); adxl.setInterruptMapping( ADXL345_INT_FREE_FALL_BIT, ADXL345_INT1_PIN ); //adxl.setInterruptMapping( ADXL345_INT_ACTIVITY_BIT, ADXL345_INT1_PIN ); //adxl.setInterruptMapping( ADXL345_INT_INACTIVITY_BIT, ADXL345_INT1_PIN ); //set interrupt actions //adxl.setInterrupt( ADXL345_INT_SINGLE_TAP_BIT, 1); //adxl.setInterrupt( ADXL345_INT_DOUBLE_TAP_BIT, 1); adxl.setInterrupt( ADXL345_INT_FREE_FALL_BIT, 1); //adxl.setInterrupt( ADXL345_INT_ACTIVITY_BIT, 1); //adxl.setInterrupt( ADXL345_INT_INACTIVITY_BIT, 1); */ }
void loop() {
//adxl.readAccel(&x, &y, &z); range = String(get_range(RANGE_FINDER_PIN), DEC); //display range lcd_write_text("Range: ", 1, 0, 0xFF, 0xFF, 0, 0); lcd_write_text(range, 1, 0, 0xFF, 0xFF, 7, 0); /* //display accelerometer readings a_x = String(x); a_y = String(y); a_z = String(z); lcd_write_text("x: ", 1, 0, 0xFF, 0xFF, 0, 1); lcd_write_text(a_x, 1, 0, 0xFF, 0xFF, 3, 1); lcd_write_text("y: ", 1, 0, 0xFF, 0xFF, 0, 2); lcd_write_text(a_y, 1, 0, 0xFF, 0xFF, 3, 2); lcd_write_text("z: ", 1, 0, 0xFF, 0xFF, 0, 3); lcd_write_text(a_z, 1, 0, 0xFF, 0xFF, 3, 3); */ //display joystick values joystick_x = analogRead(JOYSTICK_HORZ_PIN); joystick_y = analogRead(JOYSTICK_VERT_PIN); j_x = String(joystick_x, DEC); j_y = String(joystick_y, DEC); lcd_write_text("j_x: ", 1, 0, 0xFF, 0xFF, 0, 6); lcd_write_text(j_x, 1, 0, 0xFF, 0xFF, 5, 6); lcd_write_text("j_y: ", 1, 0, 0xFF, 0xFF, 0, 7); lcd_write_text(j_y, 1, 0, 0xFF, 0xFF, 5, 7);
}
int get_range(int range_pin) { int range; range = analogRead(range_pin) * 0.496; return range; }
void lcd_write_text(String text, byte mode, int size, byte color_msb, byte color_lsb, byte x, byte y) {
int i = 0; //set opaque (0x01) or transparent (0x00) Serial2.write(LCD_SET_TRANSPARENT); if (mode == 0){ Serial2.write(byte(LCD_FONT_TRANSPARENT)); } else { Serial2.write(byte(LCD_FONT_OPAQUE)); } lcd_get_reply(); delay(10);
//set location x,y //set color(0xFFFF), 2 bytes Serial2.write(LCD_DRAW_TEXT_STRING); Serial2.write(byte(x)); Serial2.write(byte(y)); switch (size){ case 0: Serial2.write(byte(LCD_FONT_SIZE_SMALL)); break; case 1: Serial2.write(byte(LCD_FONT_SIZE_MEDIUM)); break; case 2: Serial2.write(byte(LCD_FONT_SIZE_LARGE)); break; default: Serial2.write(byte(LCD_FONT_SIZE_SMALL)); } //set color, two bytes (16 bit color) sent seperately Serial2.write(byte(color_msb)); Serial2.write(byte(color_lsb)); //output text while(i < text.length()){ Serial2.write(text.charAt(i)); i++; }
//send termination byte Serial2.write(byte(LCD_TERMINATION)); lcd_get_reply(); }
byte lcd_get_reply(){ byte response = LCD_ACK; //ACK while (!Serial2.available()){ delayMicroseconds(150); } response = Serial2.read(); delay(10); return response; }
void init_lcd(){ Serial2.write(0x55); //Auto-Baud Signal delay(100); }
void init_motor_driver(){
// Initialize Motor Driver Serial Port (1) Serial1.begin(115200); delay(1000); // Set motor speed to 0 Serial1.println("1F0"); delay(10); Serial1.println("2F0");
}
void drive_forward(){ Serial1.println("1F9"); Serial1.println("2F9"); }
void drive_reverse(){ Serial1.println("1R9"); Serial1.println("2R9"); }
void drive_turn_right(){ Serial1.println("1F9"); Serial1.println("2R9");
}
void drive_turn_left(){ Serial1.println("1R9"); Serial1.println("2F9");
}
void drive_stop(){ Serial1.println("1F0"); Serial1.println("2F0"); }
|
|
|
|
|
7
|
Using Arduino / Programming Questions / Quick question on compilers
|
on: January 30, 2011, 11:48:55 pm
|
When you compile a piece of code that has files included in it. What parts get compiled? For instance, if I've created a library to take advantage of the full function of my MCP23017 I/O expander but I never call a specific function that I've coded in the header file, does that get compiled with everything and thus added onto the chip taking up some of the valuable programming space? I'm familiar with asm and such, but compilers are a little out of my league. Any thoughts? If this has been asked before, any links? Thanks for your time  -Tweed
|
|
|
|
|
8
|
Forum 2005-2010 (read only) / Interfacing / Re: My arduino project
|
on: October 26, 2010, 08:42:34 pm
|
The first project I intend to take to completion is a laser tag pack and scoring system. If this is your first project (as it is mine) I would recommend breaking everything down into learning how to activate/deactivate/read/write etc different components first. For instance, first I learned how to use LEDs, how to turn them on and off, how to use the PWM outputs to make RGB LEDs and regular LEDs pulse. Now I'm learning how to make infrared TX and RX in the manner that I want. I apologize if that is way below what you already know, but seriously, you have to learn how all the parts work before you get in over your head and find yourself not completing the project you want. There are tons of resources available here and around the web. Good Luck! (Also, here's a really good place to get started: http://www.ladyada.net/learn/arduino/index.html) Like I said, if you're way past that, my apologies. -Tweed
|
|
|
|
|
9
|
Forum 2005-2010 (read only) / Interfacing / Monitoring USB Output via Linux Terminal (w/ IR)
|
on: October 26, 2010, 08:20:37 pm
|
Hey all, many of you may be very well aware how to do this, but it took me about 45 minutes to track this information down, hopefully this can help someone  I have been developing an IR TX/RX system using two Arduinos and none of the solutions on this forum quite work for what I want to accomplish. Hopefully, I can get this done in the next week or so as I have time. Anyways, here's what I have and maybe it can help someone not waste as much time as I did! I guess I'll start with the code/setup (included in the code). /* Works with IR breakout board from Sparkfun.com Sparkfun P/N SEN-08554, it utilizes the Vishay TSOP85 Pin Out: Vcc = Arduino 5V Out = Arduino D2 (Interupt 0) Gnd = Arduino Gnd */
int interuptPin = 2; int IRPin = LOW;
void setup() { pinMode(13, OUTPUT); //For Debugging attachInterrupt(0, IRStateChange, CHANGE); Serial.begin(9600); //For Debugging }
void loop() { digitalWrite(13, LOW); }
void IRStateChange() { IRPin = digitalRead(interuptPin); digitalWrite(13, HIGH); Serial.print(IRPin); } On a windows system with this program loaded and monitoring the serial port, you can point a remote at it and get a stream of 1's and 0's. This was tested with a Philips Universal remote and a Charter Cable universal remote. On linux it is a little more tricky, but not much. Connect your arduino to the USB and make sure you get something along the lines of: usb4-2 blah blah blah ... usb4-2: FTDI USB Serial Device converter now attached to ttyUSB0 On Fedora Core 12 and with an old cruddy computer I didn't have to install any drivers and it was automatic. Then, simply use the command: screen /dev/ttyUSB0 9600 That is it and obviously ttyUSB# depends on what the OS reports your USB port # as. (google screen commands for help with screen as I am not allowed to post the link because this is my first post!) Hopefully some part of this post helped for some reason for someone  -Tweed EDIT: If you find yourself in trouble with any USB device in Linux, it is always a good idea to unplug it and sift through the ashes.
|
|
|
|
|
10
|
Forum 2005-2010 (read only) / Troubleshooting / Re: only pin 13 Works
|
on: December 27, 2010, 08:52:05 pm
|
|
That I did not know. I did try it on my Duemilanove when I got it about 4-5ish months ago and it worked, so I did not assume there would be a problem if it were just a test. Seems like a dumb mistake to make/not correct?
|
|
|
|
|
11
|
Forum 2005-2010 (read only) / Troubleshooting / Re: only pin 13 Works
|
on: December 27, 2010, 08:26:02 pm
|
|
As retrolefty pointed out, for proper LED circuits, you should put a resistor between the Digital pin on the arduino board and the long pin of the LED. This protects it and the arduino.
Those tutorials by Ladyada that I linked in the previous post are a good source for beginners. It'll teach you basic circuits and basic arduino programming.
|
|
|
|
|
13
|
Forum 2005-2010 (read only) / Troubleshooting / Re: only pin 13 Works
|
on: December 27, 2010, 08:07:11 pm
|
/* Blink Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain. */
void setup() { // initialize the digital pin as an output. pinMode(12, OUTPUT); }
void loop() { digitalWrite(12, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(12, LOW); // set the LED off delay(1000); // wait for a second }
That should work...if it isn't, there is something else going on that may be above my pay grade As it was pointed out, you should use a proper resistor (do a quick google search for a LED resistor calculator). Pin -> Resistor -> Anode (long pin) -> Cathode (short pin) in GND.
|
|
|
|
|