Loading...
  Show Posts
Pages: [1] 2 3 ... 10
1  Using Arduino / Microcontrollers / Re: TinyISP/attiny + CP2102 usb to uart bridge on: May 20, 2013, 06:28:50 pm
actually code on this page seemed to work. http://wiki.sgmk-ssam.ch/index.php/SGMKtiny only difference is the baud rate, no idea why it work work and not yours otherwise :/
2  Using Arduino / Microcontrollers / Re: TinyISP/attiny + CP2102 usb to uart bridge on: May 20, 2013, 05:36:37 pm
Don't use Knock_Bang.  Use the software serial that should be part of Tiny-core.

Code:
/*
  TinySerial
  Echo back Serial data.
 
 */

#include <SoftwareSerial.h>

// Setup serial Rx to pin PB0(D0) and Tx to pin PB1(D1)
SoftwareSerial mySerial(0,1);
int data = 0;

void setup() {               
  mySerial.begin(9600);
}

void loop() {
  if (mySerial.available()) {
    data = mySerial.read();
    mySerial.write(data);
  }
}

Note: There are some limitations with software serial Rx receiving.  Although you can use 9600 baud, it won't support back-to-back characters.  So as long as you send each data character spaced out with some delay between them then you should be fine.  Also for 9600 baud you need to be running at least the 8MHz internal clocking on the ATtiny.



I can get my example to work, but yours seems to not work :/
3  Using Arduino / Programming Questions / Re: Virtual wire problem on: May 16, 2013, 07:08:11 pm
so I was running into same problem and tried replacing said lines, however I get a new error:

Code:
error: WProgram.h: No such file or directory
4  Using Arduino / Microcontrollers / raw pins on: May 15, 2013, 10:12:32 pm
trying to convert this sketch over to attiny from arduino, however it uses raw pins and I am not quite sure how they work. Not sure if I need to convert them over to attiny or if attiny doesn't need raw pins. its basically a IR decoder here is the code:


Code:
/* Raw IR decoder sketch!
 
 This sketch/program uses the Arduno and a PNA4602 to
 decode IR received. This can be used to make a IR receiver
 (by looking for a particular code)
 or transmitter (by pulsing an IR LED at ~38KHz for the
 durations detected
 
 Code is public domain, check out www.ladyada.net and adafruit.com
 for more tutorials!
 */

// We need to use the 'raw' pin reading methods
// because timing is very important here and the digitalRead()
// procedure is slower!
//uint8_t IRpin = 2;
// Digital pin #2 is the same as Pin D2 see
// http://arduino.cc/en/Hacking/PinMapping168 for the 'raw' pin mapping
#define IRpin_PIN      PIND
#define IRpin          2

// the maximum pulse we'll listen for - 65 milliseconds is a long time
#define MAXPULSE 65000

// what our timing resolution should be, larger is better
// as its more 'precise' - but too large and you wont get
// accurate timing
#define RESOLUTION 20

// we will store up to 100 pulse pairs (this is -a lot-)
uint16_t pulses[100][2];  // pair is high and low pulse
uint8_t currentpulse = 0; // index for pulses we're storing

void setup(void) {
  Serial.begin(9600);
  Serial.println("Ready to decode IR!");
}

void loop(void) {
  uint16_t highpulse, lowpulse;  // temporary storage timing
  highpulse = lowpulse = 0; // start out with no pulse length
 
 
//  while (digitalRead(IRpin)) { // this is too slow!
    while (IRpin_PIN & (1 << IRpin)) {
     // pin is still HIGH

     // count off another few microseconds
     highpulse++;
     delayMicroseconds(RESOLUTION);

     // If the pulse is too long, we 'timed out' - either nothing
     // was received or the code is finished, so print what
     // we've grabbed so far, and then reset
     if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {
       printpulses();
       currentpulse=0;
       return;
     }
  }
  // we didn't time out so lets stash the reading
  pulses[currentpulse][0] = highpulse;
 
  // same as above
  while (! (IRpin_PIN & _BV(IRpin))) {
     // pin is still LOW
     lowpulse++;
     delayMicroseconds(RESOLUTION);
     if ((lowpulse >= MAXPULSE)  && (currentpulse != 0)) {
       printpulses();
       currentpulse=0;
       return;
     }
  }
  pulses[currentpulse][1] = lowpulse;

  // we read one high-low pulse successfully, continue!
  currentpulse++;
}

void printpulses(void) {
  Serial.println("\n\r\n\rReceived: \n\rOFF \tON");
  for (uint8_t i = 0; i < currentpulse; i++) {
    Serial.print(pulses[i][0] * RESOLUTION, DEC);
    Serial.print(" usec, ");
    Serial.print(pulses[i][1] * RESOLUTION, DEC);
    Serial.println(" usec");
  }
 
  // print it in a 'array' format
  Serial.println("int IRsignal[] = {");
  Serial.println("// ON, OFF ");
  for (uint8_t i = 0; i < currentpulse-1; i++) {
    //Serial.print("\t"); // tab
    Serial.print("pulseIR(");
    Serial.print(pulses[i][1] * RESOLUTION , DEC);
    Serial.print(");");
    Serial.println("");
    //Serial.print("\t");
    Serial.print("delayMicroseconds(");
    Serial.print(pulses[i+1][0] * RESOLUTION , DEC);
    Serial.println(");");

  }
  //Serial.print("\t"); // tab
  Serial.print("pulseIR(");
  Serial.print(pulses[currentpulse-1][1] * RESOLUTION, DEC);
  Serial.print(");");

}

any ideas?
5  Using Arduino / Microcontrollers / Re: TinyISP/attiny + CP2102 usb to uart bridge on: May 06, 2013, 05:43:28 pm
Do you have sample code of what you are trying?

And any schematics or pictures?



Code:
#define KNOCK_BANG 1
#include <TinyDebugKnockBang.h>
 
#ifdef KNOCK_BANG
#define Serial Debug
#endif
void setup() {
    Serial.begin( 9600 );
}
 
void loop() {
    delay(1000);
    Serial.println("Can it be true?! An attiny serial monitor indeed!"); // debug output
}

thats the sketch. and as for how I am connecting it is simply gnd to gnd 3.3v to vcc on attiny and then that MISO and MOSI connections on the attiny from the uart bridge, its really simple connection. I can get it to work with arduino but not this core because I need to be able to send that "!" to initiate the serial monitor.
6  Using Arduino / Microcontrollers / TinyISP/attiny + CP2102 usb to uart bridge on: May 05, 2013, 03:37:45 pm
I am trying to send data to my attiny via UART. Not sure if I am missing something. I am using the PB1(MISO) and PB0 (MOSI) pins but no luck. I've tried the CP2102 with arduino and it works well, but having some issues with attiny.

Reason I need to send data is because it uses a command to start the monitor, and I can't start it unless I am able to send a "!" to it.

edit: just to be clear I can read the serial data from arduino (using knockbang), its getting it to send the '!" command to initialize reading from the CP2102 that is giving me issues.
7  Using Arduino / General Electronics / Re: Do I really need to solder headers to a shield? Or can I just plug it in? on: April 05, 2013, 10:43:55 pm
I recently purchased an MP3 Player Shield for my Arduino. I bought a couple of headers to run through the shield's holes down to my arduino. The shield's "Quick Start" Guide is telling me to solder the headers with the shield. Is this TRULY necessary (for testing purposes)? Or could I just plug it in and down to the Arduino.

Thanks!

P.S. Would I need to use all 4 headers? 2x 6pin and 2x 8pin?

its not REALLY necessary to solder, I have used things like alligator clips for some sensors and boards, but really you will save yourself a lot of headache if you just solder it. Is there any reason you wouldn't want to solder right away? Only reason I haven't soldered in the past was when I wasn't sure the case something was going in, so I would just alligator clip it down then check continuity and plug it in temporarily.
8  Using Arduino / Programming Questions / Re: void value not ignored as it ought to be on: April 05, 2013, 08:34:14 pm
Oh, here it is. 
Code:
for(int i = 0; i < numberOfSensors; i++){
     cs_sensor[i] = new CapacitiveSensor(capSenseSend,sensorPin);
   }

I had the problem right, but when I went looking for the one that was wrong I assumed that you had left this fixed.  sensorPin IS an array and needs an index.

Post 20 you said you fixed it.  Post 24 when you post new code it is still wrong.

oh, sorry I wasn't clear. I had fixed it to say:

Code:
cs_sensor[i] = new CapacitiveSensor(capSenseSend,sensorPin[i]);

just didn't post the code as I should have. I wasn't sure if that change has then set the next error into place, or if it was a correct fix. It seems to have fixed it, after I realized I wasn't referencing the correct Object later in the code. I am further in now, I think rest of these errors I can handle. thanks for your patience smiley
9  Using Arduino / Programming Questions / Re: void value not ignored as it ought to be on: April 05, 2013, 08:22:02 pm
Code:
Serial.print(allValues[0]); Serial.print(" , "); Serial.print(allValues[1]); delay(10);

And I'm betting this line will give you an allValues not declared in this scope error.  I don't see it declared anywhere anyway.

EDIT:  Found it in the previous code, but it was commented out there. 

I am kind of fixing it as I go, probably a bad idea. Reason is I am converting this from messy functions to more Class based. Those will be replaced by the classes, but I feel like I need to get the classes working first since they are so new to me, then I can make my way down the list. Right now I cant even get the class to pass correct values. But I guess I will read more about pointers....
10  Using Arduino / Programming Questions / Re: void value not ignored as it ought to be on: April 05, 2013, 08:19:48 pm
Googling for pointer and c++ gives a ton of stuff.  Many many tutorials that explain what a pointer is.  Once you know that it should be obvious that you can't convert one to an intended type. 

But even without that, I told you how to fix it.  pin numbers is an array.  You're using it without an index.  That won't work. 

maybe I am misunderstanding but pinNumber is an int, not an array. are you looking at ledPin or sensorPin maybe? those are different and in fact an array.
11  Using Arduino / Programming Questions / Re: void value not ignored as it ought to be on: April 05, 2013, 08:04:31 pm
Here are two more illegal conversions from byte pointer to uint8_t

Code:
void fadeLedIn(int pinNumber){
  for(int j = 0; j <= 255; j+=10){
    analogWrite(pinNumber,j);
    delay(10);
  } 
}

void fadeLedOut(int pinNumber){
  for(int j = 255; j >= 0; j-=10){
    analogWrite(pinNumber,j);
    delay(10);
  } 
  digitalWrite(pinNumber, LOW);
}

Go through your code and fix all these.  If you are going to use the array you'll need to put the index with it.  Get all that fixed, and post us new code to look at. 

I would fix it if I knew what was wrong to be honest. this section of code has compiled fine in the past, not sure what would be wrong with it. I don't even know how to look up what that "illegal conversions from byte pointer to uint8_t" error is, google isn't giving me anything.
12  Using Arduino / Programming Questions / Re: void value not ignored as it ought to be on: April 05, 2013, 07:55:53 pm
The array of pointers is local to setup(). Pretty useless there.

oh oops, seems moving the pointer outside the setup function doesn't seem to help either, same error:

Code:
#include <CapacitiveSensor.h>
#include "Letter.h"

const byte capSenseSend = 2;

const byte numberOfSensors = 2;
Letter letters[numberOfSensors]; // a-z

const byte sensorPin[] = { 22, 23 };
const byte ledPin[] = { 8, 9 };

CapacitiveSensor *cs_sensor[numberOfSensors];
  
void setup(){
   Serial.begin(19200);
   delay(100);

   for(int i = 0; i < numberOfSensors; i++){
     cs_sensor[i] = new CapacitiveSensor(capSenseSend,sensorPin);
   }
  
   // setup LEDs
   for(int i = 0; i < numberOfSensors; i++){
     pinMode(ledPin[i],OUTPUT);
     digitalWrite(ledPin[i], LOW);  
   }

   setSampleSize();  
}

void loop(){  
    setSensorValue();
    checkIfButtonPressed();
    delay(100);
}

void setSampleSize(){
  for(int i = 0; i < numberOfSensors; i++){
    letters[i].setSampleAmount(5);
  }
}

void setSensorValue(){
  for(int i = 0; i < numberOfSensors; i++){
    letters.setCurrentReading(cs_sensor[i]->capacitiveSensor(50));  
  }
}

void checkIfButtonPressed(){
  for(int i = 0; i < numberOfSensors; i++){
    letters[i].checkIfIsOn(cs_sensor[i]);
  }
}

void fadeLedIn(int pinNumber){
  for(int j = 0; j <= 255; j+=10){
    analogWrite(pinNumber,j);
    delay(10);
  }  
}

void fadeLedOut(int pinNumber){
  for(int j = 255; j >= 0; j-=10){
    analogWrite(pinNumber,j);
    delay(10);
  }  
  digitalWrite(pinNumber, LOW);
}

void sendSerialData(int buttonTouched){
  delay(10); Serial.print("Data,");
  delay(10); Serial.print(buttonTouched);
  delay(10); Serial.print(",");
  Serial.print("sensors : ");
  Serial.print(allValues[0]); Serial.print(" , "); Serial.print(allValues[1]); delay(10);
  Serial.print("\n");
  delay(10);
}

earlier I mentioned I set that line with the error to: cs_sensor = new CapacitiveSensor(capSenseSend,sensorPin);
which seems like what it is suppose to be, however farther down I get:

error:  request for member 'setCurrentReading' in 'letters', which is of non-class type 'Letter [2]'
for:
Code:
letters.setCurrentReading(cs_sensor[i]->capacitiveSensor(50));

so I am not sure if this is correct thing to do.
13  Using Arduino / Programming Questions / Re: void value not ignored as it ought to be on: April 05, 2013, 07:39:11 pm
Just follow exactly what the compiler told you.  The setSensorValue is missing an array index there.

seems to stop way before that on: cs_sensor = new CapacitiveSensor(capSenseSend,sensorPin); with error:  error: invalid conversion from 'const byte*' to 'uint8_t'

I gave it an array index like so just now:

Code:
void setSensorValue(){
  for(int i = 0; i < numberOfSensors; i++){
    letters.setCurrentReading(cs_sensor[i]->capacitiveSensor(50));  
  }
}

same error. thats is the problem, no idea what the error means, and can't seem to find anything on google for it :/
14  Using Arduino / Programming Questions / Re: void value not ignored as it ought to be on: April 05, 2013, 07:26:03 pm
You need to post your current code, so that we can see that you made all the required changes, correctly. And so we can replicate (and solve) the problem more easily.

I did, its on the last page might have missed it, other than the changes you suggested. here it is again though just in case:

Code:
#include <CapacitiveSensor.h>
#include "Letter.h"

const byte capSenseSend = 2;

const byte numberOfSensors = 2;
Letter letters[numberOfSensors]; // a-z

const byte sensorPin[] = { 22, 23 };
const byte ledPin[] = { 8, 9 };

//int allValues[numberOfSensors];

void setup(){
   Serial.begin(19200);
   delay(100);
   
   CapacitiveSensor *cs_sensor[numberOfSensors];
   
   for(int i = 0; i < numberOfSensors; i++){
     cs_sensor[i] = new CapacitiveSensor(capSenseSend,sensorPin);
   }
 
   // setup LEDs
   for(int i = 0; i < numberOfSensors; i++){
     pinMode(ledPin[i],OUTPUT);
     digitalWrite(ledPin[i], LOW); 
   }
   //cs_a.set_CS_AutocaL_Millis(0xFFFFFFFF);

   setSampleSize();   
}

void loop(){ 
    setSensorValue();
    checkIfButtonPressed();
    delay(100);
}

void setSampleSize(){
  for(int i = 0; i < numberOfSensors; i++){
    letters[i].setSampleAmount(5);
  }
}

void setSensorValue(){
  for(int i = 0; i < numberOfSensors; i++){
    letters.setCurrentReading(cs_sensor->capacitiveSensor(50)); 
  }
}

void checkIfButtonPressed(){
  for(int i = 0; i < numberOfSensors; i++){
    letters[i].checkIfIsOn(cs_sensor[i]);
  }
}

void fadeLedIn(int pinNumber){
  for(int j = 0; j <= 255; j+=10){
    analogWrite(pinNumber,j);
    delay(10);
  } 
}

void fadeLedOut(int pinNumber){
  for(int j = 255; j >= 0; j-=10){
    analogWrite(pinNumber,j);
    delay(10);
  } 
  digitalWrite(pinNumber, LOW);
}

void sendSerialData(int buttonTouched){
  delay(10); Serial.print("Data,");
  delay(10); Serial.print(buttonTouched);
  delay(10); Serial.print(",");
  Serial.print("sensors : ");
  Serial.print(allValues[0]); Serial.print(" , "); Serial.print(allValues[1]); delay(10);
  Serial.print("\n");
  delay(10);
}

Letters.h:
Code:
#ifndef LETTER_H
#define LETTER_H

class Letter {
  public:
    Letter();
    double getAverage(int sample);
    void setSampleAmount(int changeSampleTo);
    void setLastReading(int theLastReading);
    void setCurrentReading(int theCurrentReading);
    void checkIfisOn(int curentSensorValue[]);
    int getCurrentReading();
    int getLastReading();
    int aValue;
    int lastReading;
    int currentReading;
  private:
    int _sampleAmount;
    double _tempAverage,
           _capacitiveAverage;
    double _runningAverage[100];
};

#endif

Letter.ino:

Code:
#include "Letter.h" // "" for files within same folder as sketch...?

Letter::Letter() {
  _sampleAmount = 5;
  _tempAverage = 0;
  _capacitiveAverage = 0; 
  lastReading = 0;
  currentReading = 0;
  //long _runningAverage[_sampleAmount];
};

void Letter::setSampleAmount(int changeSampleTo){
  _sampleAmount = changeSampleTo;
};

void Letter::setLastReading(int theLastReading){
  lastReading = theLastReading;
}

void Letter::setCurrentReading(int theCurrentReading){
  currentReading = theCurrentReading;
}

int Letter::getLastReading(){
  return lastReading;
}

int Letter::getCurrentReading(){
  return currentReading;
}

double Letter::getAverage(int sample) {
  for(int i = 0; i < _sampleAmount; i++){
    _runningAverage[i] = sample;
  }
  // reset _tempAverage
  _tempAverage = 0;
  // add all the samples up
  for(int i = 0; i < _sampleAmount; i++){
    _tempAverage += _runningAverage[i];
  }
  // divide by number of samples to get average
  _capacitiveAverage =  _tempAverage/_sampleAmount;
  return _capacitiveAverage;
}


void Letter::checkIfisOn(){
  boolean firstTime = true;
  int firstRelease = 0;
  const int threshold = 55;
  int differenceReading = curentSensorValue-lastReading;
  if(differenceReading > threshold && firstTime == true){
    sendSerialData(i);
    fadeLedIn(ledPin[i]);
  if((currentReading-lastReading) < threshold){
    digitalWrite(ledPin[i], LOW);
    fadeLedOut(ledPin[i]);}
    lastReading[i] = currentReading[i];
    firstTime = false;
  }
}
15  Using Arduino / Programming Questions / Re: void value not ignored as it ought to be on: April 05, 2013, 06:57:23 pm
If Paul had that in code tags you'd see that there is a couple of array indexes there that aren't showing up.  Should look like:
Code:
for(int i = 0; i < numberOfSensors; i++)
   { // Down here where it belongs!
     cs_sensor[i] = new CapacitiveSensor(capSenseSend,sensorPin[i]);
   }



Yes, tried this too. same error.

also tried:
Code:
cs_sensor[i] = new CapacitiveSensor(capSenseSend,sensorPin[i]);

but this gave error:  request for member 'setCurrentReading' in 'letters', which is of non-class type 'Letter [2]'
Pages: [1] 2 3 ... 10