Show Posts
Pages: [1] 2
1  Development / Suggestions for the Arduino Project / Suggestion: Put IDE Compiler/Programming Output In Separate Window on: February 20, 2014, 09:37:19 pm
Hello,

I'm sure someone has suggested this before, but it would be really nice if you could show verbose output for compiling and programming in a separate window.  Maybe as an option either the traditional display or the option to display it in a separate window?

Has this been suggested before?  What are other's thoughts?

Thanks for a great environment/hardware to use and learn from.

-Mat
2  Development / Other Software Development / Re: Compiler error associated with Switch (using documentation) on: January 19, 2014, 09:09:03 pm
Also, if you uncomment the line after the default: label or add break; or any statement that ends with a ';' the error goes away.
3  Development / Other Software Development / Re: Compiler error associated with Switch (using documentation) on: January 19, 2014, 09:03:46 pm
Sorry for the late reply.  I didn't see this until today.  Here is some code that produces the compiler error:

Error:
Code:
lightbar.cpp: In member function 'void lightbar::set_led(int, int, int, int)':
lightbar.cpp:81: error: expected primary-expression before '}' token
lightbar.cpp:81: error: expected `;' before '}' token

This code is just a little project I am working on and completely unfinished, but if this is a rare case I wanted to be able to demonstrate it:

Relevant code:
Main sketch:
Code:

#include "Tlc5940.h"
#include "lightbar.h"

lightbar lightbar;

int counter = 0;
int d = 30;
int r, g, b;

void setup() {
 
  lightbar.init();

  r = 0;
  g = 0;
  b = 0;

}

void loop() {
 
  for(int i=0; i <=1000; i++){
    lightbar.set_led(0, i, 0, 0);
    lightbar.set_led(1, i, 0, 0);
    lightbar.set_led(2, i, 0, 0);
    lightbar.set_led(3, i, 0, 0);
    lightbar.set_led(4, i, 0, 0);
    delay(d);
  }

  for(int i=1000; i <=1000; i++){
    lightbar.set_led(0, 500, 0, i);
    lightbar.set_led(1, 500, 0, i);
    lightbar.set_led(2, 500, 0, i);
    lightbar.set_led(3, 500, 0, i);
    lightbar.set_led(4, 500, 0, i);
    delay(d);   
  }
  for(int i=1000; i > 0; i--){
    lightbar.set_led(0, i, 0, i);
    lightbar.set_led(1, i, 0, i);
    lightbar.set_led(2, i, 0, i);
    lightbar.set_led(3, i, 0, i);
    lightbar.set_led(4, i, 0, i);
    delay(d);   
  }
  for(int i=0; i <=1000; i++){
    lightbar.set_led(0, 0, i, 0);
    lightbar.set_led(1, 0, i, 0);
    lightbar.set_led(2, 0, i, 0);
    lightbar.set_led(3, 0, i, 0);
    lightbar.set_led(4, 0, i, 0);
    delay(d);
  }

}


lightbar.cpp:
Code:

#include "Arduino.h"
#include "Tlc5940.h"
#include "lightbar.h"

lightbar::lightbar(){
  //Constructor, empty for now
}

// calls Tlc5940.h init function and clears any values on the chip
void lightbar::init(){

  //initialize tlc(s)
  Tlc.init();
  //reset pins to off
  Tlc.set(0, 0); 
  Tlc.set(1, 0); 
  Tlc.set(2, 0); 
  Tlc.set(3, 0); 
  Tlc.set(4, 0); 
  Tlc.set(5, 0); 
  Tlc.set(6, 0); 
  Tlc.set(7, 0); 
  Tlc.set(8, 0); 
  Tlc.set(9, 0); 
  Tlc.set(10, 0); 
  Tlc.set(11, 0); 
  Tlc.set(12, 0); 
  Tlc.set(13, 0); 
  Tlc.set(14, 0); 
  Tlc.set(15, 0);
  //send data
  Tlc.update();
 
}

void lightbar::set_led(int led, int r, int g, int b){

 
  switch (led) {
 
    case 0:
     
      Tlc.set(0, r);
      Tlc.set(1, b);
      Tlc.set(2, g);
      Tlc.update();
      break;

    case 1:
      Tlc.set(3, r);
      Tlc.set(4, b);
      Tlc.set(5, g);
      Tlc.update();
      break;

    case 2:
      Tlc.set(6, r);
      Tlc.set(7, b);
      Tlc.set(8, g);
      Tlc.update();
      break;

    case 3:
      Tlc.set(9, r);
      Tlc.set(10, b);
      Tlc.set(11, g);
      Tlc.update();
      break;

    case 4:
      Tlc.set(12, r);
      Tlc.set(13, b);
      Tlc.set(14, g);
      Tlc.update();
      break;

    default:
      //Tlc.update();
     
  }

}

void lightbar::set_all(int color){

  //reset pins to off
  Tlc.set(0, color); 
  Tlc.set(1, color); 
  Tlc.set(2, color); 
  Tlc.set(3, color); 
  Tlc.set(4, color); 
  Tlc.set(5, color); 
  Tlc.set(6, color); 
  Tlc.set(7, color); 
  Tlc.set(8, color); 
  Tlc.set(9, color); 
  Tlc.set(10, color); 
  Tlc.set(11, color); 
  Tlc.set(12, color); 
  Tlc.set(13, color); 
  Tlc.set(14, color); 
  Tlc.set(15, color);
  //send data
  Tlc.update();
 
}

void lightbar::clear_all(){

    //reset pins to off
  Tlc.set(0, 0); 
  Tlc.set(1, 0); 
  Tlc.set(2, 0); 
  Tlc.set(3, 0); 
  Tlc.set(4, 0); 
  Tlc.set(5, 0); 
  Tlc.set(6, 0); 
  Tlc.set(7, 0); 
  Tlc.set(8, 0); 
  Tlc.set(9, 0); 
  Tlc.set(10, 0); 
  Tlc.set(11, 0); 
  Tlc.set(12, 0); 
  Tlc.set(13, 0); 
  Tlc.set(14, 0); 
  Tlc.set(15, 0);
  //send data
  Tlc.update();

}

lightbar.h:
Code:

#ifndef lightbar_h

  #define lightbar_h
  #define MAX_BRIGHTNESS 1023
 
  #include "Arduino.h"
   
  class lightbar
  {
    public:
   
      lightbar();
      void init();
      void set_led(int led, int r, int g, int b);   
      void set_all(int color);
      void clear_all();
   
    private:
     
      //!
   
  };

#endif


Judging by your response, I'm guessing it may not occur in a normal sketch, but my problem may be associated with the switch statement being in a .cpp file?

-Mat
4  Development / Other Software Development / Compiler error associated with Switch (using documentation) on: January 16, 2014, 10:59:05 pm
Hello,

The compiler was giving me a rather hard to track error, I was getting the dreaded "expected primary-expression before '}' token" error.  I looked through the code 50 times and had all my }'s and ;'s in order.  What I found out is that if you use "default:" without a break; or without some sort of statement that ends in ";" while using the switch() statement you will get this error.

The documentation has commented lines in the example code after the default: label (http://arduino.cc/en/Reference/SwitchCase).  However if you ran the code as is in the example code you would get this same error.

I know this may be minor, but it took me a good deal of time to track down the error until I remembered the comment everything out and then slowly un-comment everything trick.

I hope I have given enough detail and I hope this may be useful, it is getting late and the caffeine isn't helping anymore.  Also, I hope this is the appropriate place to post this, as the reference page led me here.

Thanks.

-Mat
5  Using Arduino / Programming Questions / Re: SoftwareSerial (on ATtiny85 8 MHz core) printing "boxes" to IDE Serial Display on: January 29, 2013, 11:15:38 pm
Thank you so much, that fixed it.  I've just recently begun experimenting with the Tinys.  I've seen countless posts by you too while trying to figure this out, how do you find the time man?

-Tweed
6  Using Arduino / Programming Questions / Re: SoftwareSerial (on ATtiny85 8 MHz core) printing "boxes" to IDE Serial Display on: January 29, 2013, 10:51:57 pm
I have the ATtiny85 @ 8 MHz (internal oscillator; BOD disabled) core selected in the IDE, I'm programming it with the AVR ISP mkII.
7  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):
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.  smiley-razz

-Tweed

8  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:

Code:
:/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
9  Using Arduino / Programming Questions / Re: Local vs Global Var problem on: May 30, 2012, 07:12:43 pm
Thank you very much for your help.

-Tweed
10  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:
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:
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");
 
}
11  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 smiley

-Tweed
12  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
13  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 smiley

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).

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:
Code:
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:
Code:
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 smiley

-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.
14  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?
15  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.
Pages: [1] 2