Show Posts
Pages: [1]
1  Using Arduino / Sensors / IRremote breaking loop on: September 12, 2013, 09:59:56 pm
I want an infinite loop to start when I hit a button on the IR remote then stop when I hit another.

Code:
case 0xFF629D:
  for(int i = 0; i < 5;)
{
  setColor(255, 0, 0);  // red
  delay(100);
  setColor(0, 0, 255);  // blue
  delay(100);
}  
    Serial.println(" CH             ");
    break;

I understand I should probably be using a While loop, but I was unsure how to go about it.  Thanks for any help.
2  Using Arduino / Programming Questions / Compiling error with IRremote on: January 19, 2013, 10:21:30 am
Getting the following compiling error when trying to run IRtest from the example library.

Any help would be greatly appreciated.

ArduinoIRremotemaster\IRremote.cpp.o: In function `MATCH(int, int)':
/IRremoteInt.h:176: multiple definition of `MATCH(int, int)'
IRtest.cpp.o:C:\Users\Phil\Documents\Arduino\libraries\ArduinoIRremotemaster/IRremoteInt.h:176: first defined here
ArduinoIRremotemaster\IRremote.cpp.o: In function `MATCH_MARK(int, int)':
/IRremoteInt.h:177: multiple definition of `MATCH_MARK(int, int)'
IRtest.cpp.o:C:\Users\Phil\Documents\Arduino\libraries\ArduinoIRremotemaster/IRremoteInt.h:177: first defined here
ArduinoIRremotemaster\IRremote.cpp.o: In function `MATCH_SPACE(int, int)':
/IRremoteInt.h:178: multiple definition of `MATCH_SPACE(int, int)'
IRtest.cpp.o:C:\Users\Phil\Documents\Arduino\libraries\ArduinoIRremotemaster/IRremoteInt.h:178: first defined here


IRtest code:

/*
 * IRremote: IRtest unittest
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 *
 * Note: to run these tests, edit IRremote/IRremote.h to add "#define TEST"
 * You must then recompile the library by removing IRremote.o and restarting
 * the arduino IDE.
 */

#include <IRremote.h>
#include <IRremoteInt.h>

// Dumps out the decode_results structure.
// Call this after IRrecv::decode()
// void * to work around compiler issue
//void dump(void *v) {
//  decode_results *results = (decode_results *)v
void dump(decode_results *results) {
  int count = results->rawlen;
  if (results->decode_type == UNKNOWN) {
    Serial.println("Could not decode message");
  }
  else {
    if (results->decode_type == NEC) {
      Serial.print("Decoded NEC: ");
    }
    else if (results->decode_type == SONY) {
      Serial.print("Decoded SONY: ");
    }
    else if (results->decode_type == RC5) {
      Serial.print("Decoded RC5: ");
    }
    else if (results->decode_type == RC6) {
      Serial.print("Decoded RC6: ");
    }
    Serial.print(results->value, HEX);
    Serial.print(" (");
    Serial.print(results->bits, DEC);
    Serial.println(" bits)");
  }
  Serial.print("Raw (");
  Serial.print(count, DEC);
  Serial.print("): ");

  for (int i = 0; i < count; i++) {
    if ((i % 2) == 1) {
      Serial.print(results->rawbuf*USECPERTICK, DEC);
    }
    else {
      Serial.print(-(int)results->rawbuf*USECPERTICK, DEC);
    }
    Serial.print(" ");
  }
  Serial.println("");
}

IRrecv irrecv(0);
decode_results results;

class IRsendDummy :
public IRsend
{
public:
  // For testing, just log the marks/spaces
#define SENDLOG_LEN 128
  int sendlog[SENDLOG_LEN];
  int sendlogcnt;
  IRsendDummy() :
  IRsend() {
  }
  void reset() {
    sendlogcnt = 0;
  }
  void mark(int time) {
    sendlog[sendlogcnt] = time;
    if (sendlogcnt < SENDLOG_LEN) sendlogcnt++;
  }
  void space(int time) {
    sendlog[sendlogcnt] = -time;
    if (sendlogcnt < SENDLOG_LEN) sendlogcnt++;
  }
  // Copies the dummy buf into the interrupt buf
  void useDummyBuf() {
    int last = SPACE;
    irparams.rcvstate = STATE_STOP;
    irparams.rawlen = 1; // Skip the gap
    for (int i = 0 ; i < sendlogcnt; i++) {
      if (sendlog < 0) {
        if (last == MARK) {
          // New space
          irparams.rawbuf[irparams.rawlen++] = (-sendlog - MARK_EXCESS) / USECPERTICK;
          last = SPACE;
        }
        else {
          // More space
          irparams.rawbuf[irparams.rawlen - 1] += -sendlog / USECPERTICK;
        }
      }
      else if (sendlog > 0) {
        if (last == SPACE) {
          // New mark
          irparams.rawbuf[irparams.rawlen++] = (sendlog + MARK_EXCESS) / USECPERTICK;
          last = MARK;
        }
        else {
          // More mark
          irparams.rawbuf[irparams.rawlen - 1] += sendlog / USECPERTICK;
        }
      }
    }
    if (irparams.rawlen % 2) {
      irparams.rawlen--; // Remove trailing space
    }
  }
};

IRsendDummy irsenddummy;

void verify(unsigned long val, int bits, int type) {
  irsenddummy.useDummyBuf();
  irrecv.decode(&results);
  Serial.print("Testing ");
  Serial.print(val, HEX);
  if (results.value == val && results.bits == bits && results.decode_type == type) {
    Serial.println(": OK");
  }
  else {
    Serial.println(": Error");
    dump(&results);
  }


void testNEC(unsigned long val, int bits) {
  irsenddummy.reset();
  irsenddummy.sendNEC(val, bits);
  verify(val, bits, NEC);
}
void testSony(unsigned long val, int bits) {
  irsenddummy.reset();
  irsenddummy.sendSony(val, bits);
  verify(val, bits, SONY);
}
void testRC5(unsigned long val, int bits) {
  irsenddummy.reset();
  irsenddummy.sendRC5(val, bits);
  verify(val, bits, RC5);
}
void testRC6(unsigned long val, int bits) {
  irsenddummy.reset();
  irsenddummy.sendRC6(val, bits);
  verify(val, bits, RC6);
}

void test() {
  Serial.println("NEC tests");
  testNEC(0x00000000, 32);
  testNEC(0xffffffff, 32);
  testNEC(0xaaaaaaaa, 32);
  testNEC(0x55555555, 32);
  testNEC(0x12345678, 32);
  Serial.println("Sony tests");
  testSony(0xfff, 12);
  testSony(0x000, 12);
  testSony(0xaaa, 12);
  testSony(0x555, 12);
  testSony(0x123, 12);
  Serial.println("RC5 tests");
  testRC5(0xfff, 12);
  testRC5(0x000, 12);
  testRC5(0xaaa, 12);
  testRC5(0x555, 12);
  testRC5(0x123, 12);
  Serial.println("RC6 tests");
  testRC6(0xfffff, 20);
  testRC6(0x00000, 20);
  testRC6(0xaaaaa, 20);
  testRC6(0x55555, 20);
  testRC6(0x12345, 20);
}

void setup()
{
  Serial.begin(9600);
  test();
}

void loop() {
}
3  Using Arduino / Interfacing w/ Software on the Computer / Re: Printing temperature probe data in Processing on: January 13, 2013, 09:00:52 pm
Understood

I was planning on using commas for delimiting between temperatures.

I understand they are headers and titles.  How to create text for the data was my main question.

Ok I have the first temperature working with serialEvent().  Getting there.
4  Using Arduino / Interfacing w/ Software on the Computer / Printing temperature probe data in Processing on: January 13, 2013, 06:01:56 pm

I want to create a GUI using processing to display 3 temperature probes I have connected to my  Arduino.

 

I am able to get Processing to read the data. I have not seen anything about how to display this data in a window with text.

 

Any help I can get would be greatly appreciated.  I am a very new to this program.

 

Example of the serial data processing is getting from the println.  3 printsof it.

 

70.25
70.25
70.25
70.2570
.2570.25
70.25
70.25
70.25


 

Thanks

 

Phil

 

Processing code:

 

// Example by Tom Igoe

import processing.serial.*;

PFont f;

Serial myPort;  // The serial port

void setup() {
  // List all the available serial ports:
  size(480, 480);
  println(Serial.list());
  // Open the port you are using at the rate you want:
  myPort = new Serial(this, Serial.list()[1], 9600);
  f = createFont("Arial",16,true);
}

void draw() {
 
  background(255);
  textFont(f,16);                 
  fill(0);
  text("TEMPERATURES:",10,50); 
  text("Temp 1:",10,100);
  text("Temp 2:",10,150); 
  text("Temp 3:",10,200);

 
  while (myPort.available() > 0) {
    String inBuffer = myPort.readString();   
    if (inBuffer != null) {
      println(inBuffer);
     

    }
  }
}



 

Arduino Code:

 

#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// Assign the addresses of your 1-Wire temp sensors.


DeviceAddress T1 = { 0x28, 0x0E, 0xFF, 0xE9, 0x03, 0x00, 0x00, 0xFA };
DeviceAddress T2 = { 0x28, 0x0E, 0xFF, 0xE9, 0x03, 0x00, 0x00, 0xFA  };
DeviceAddress T3 = { 0x28, 0x0E, 0xFF, 0xE9, 0x03, 0x00, 0x00, 0xFA  };

 

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(T1, 10);
  sensors.setResolution(T2, 10);
  sensors.setResolution(T3, 10);
}

 

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) {
    Serial.print(" Error");
  } else {
    Serial.print(DallasTemperature::toFahrenheit(tempC));
  }
}

 

void loop(void)
{
  delay(2000);
  sensors.requestTemperatures();
 

  printTemperature(T1);

  printTemperature(T2);

  printTemperature(T3);
}

 

 

 
1

5  Using Arduino / Sensors / Re: Converting DS18B20 output to integer value on: January 08, 2013, 01:04:00 pm
I'm having no problem getting the Thermometor to work.  Its getting it to work with the guino gui that is giving me fits.  Tells me its not an INT and gets an error.
6  Using Arduino / Sensors / Converting DS18B20 output to integer value on: January 07, 2013, 10:17:20 pm
Was wondering how to convert the DS18B20 output to integer value.  For use with the Guino graphvalue.
7  Using Arduino / Programming Questions / Re: OneWire error message on: January 07, 2013, 03:52:00 pm
Thank you

I knew it was simple.  I put the library in the right spot and it works now.

8  Using Arduino / Programming Questions / OneWire error message on: January 07, 2013, 02:49:06 pm
I'm new to Arduino and I'm trying to get the address for a onewire temp probe.

When I try to verify the one_wire_address_finder code in arduino 1.03 I get the following errors

one_wire_address_finder:9: error: 'OneWire' does not name a type
one_wire_address_finder.pde: In function 'void discoverOneWireDevices()':
one_wire_address_finder:23: error: 'ds' was not declared in this scope
one_wire_address_finder:35: error: 'OneWire' has not been declared
one_wire_address_finder:41: error: 'ds' was not declared in this scope

Code is below

// This sketch looks for 1-wire devices and
// prints their addresses (serial number) to
// the UART, in a format that is useful in Arduino sketches
// Tutorial:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

#include <OneWire.h>

OneWire  ds(3);  // Connect your 1-wire device to pin 3

void setup(void) {
  Serial.begin(9600);
  discoverOneWireDevices();
}

void discoverOneWireDevices(void) {
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];
 
  Serial.print("Looking for 1-Wire devices...\n\r");
  while(ds.search(addr)) {
    Serial.print("\n\rFound \'1-Wire\' device with address:\n\r");
    for( i = 0; i < 8; i++) {
      Serial.print("0x");
      if (addr < 16) {
        Serial.print('0');
      }
      Serial.print(addr, HEX);
      if (i < 7) {
        Serial.print(", ");
      }
    }
    if ( OneWire::crc8( addr, 7) != addr[7]) {
        Serial.print("CRC is not valid!\n");
        return;
    }
  }
  Serial.print("\n\r\n\rThat's it.\r\n");
  ds.reset_search();
  return;
}

void loop(void) {
  // nothing to see here
}

I know its probably something simple I'm missing.

Any help you can give me would be greatly appreciated

Thanks

Phil

Pages: [1]