Show Posts
Pages: 1 ... 5 6 [7] 8 9 ... 13
91  Using Arduino / Programming Questions / still run functions while in delay on: March 05, 2013, 10:44:17 pm
seem to have a problem that while a function is running which has some delays and digitally increments the brightness of an LED it seems I cannot run anything in between. is there a way to check for example, a button press, while something is in a delay or being incremented?
92  Using Arduino / Programming Questions / Re: ternary operator using HIGH and LOW on: March 03, 2013, 11:14:37 pm
Delta_G, this totally fixed it! silly me, I see what was happening now. I may be using this improperly, but this seems to work:

Code:
void cycleLEDs(){
  const int setupLedSpeed = 80;
 
  int isHighLow = LOW;

  for(int i = 0; i < 10; i++){
    digitalWrite(led[0], isHighLow);
    delay(setupLedSpeed);
    digitalWrite(led[1], isHighLow);
    delay(setupLedSpeed);
    digitalWrite(led[2], isHighLow);
    delay(setupLedSpeed);
    isHighLow = (isHighLow == HIGH)? LOW : HIGH;
  }
}

working on refactoring the rest too so I dont have so much redundant digitalWrites/delays smiley
93  Using Arduino / Programming Questions / Re: turnary operator using HIGH and LOW on: March 03, 2013, 11:10:53 pm
You are setting HighLowToggle to be HIGH in the comparison.  But then you never change the variable isHighLow.  So every time that comparison gets run isHighLow is still HIGH so the comparison is true and HighLowToggle gets set to HIGH.  Make isHighLow a static variable so it doesn't get reinitialized to HIGH every time you call the function and then include a line somewhere that toggles the variable isHighLow and you would be there.

ok I think I see what you are saying. I will try to work this in. thank you.
94  Using Arduino / Programming Questions / Re: turnary operator using HIGH and LOW on: March 03, 2013, 11:01:55 pm
Code:
  boolean isHighLow = HIGH;
  boolean HighLowToggle = (isHighLow == HIGH)? HIGH : LOW;
 

Hopefully the ternery operator is being used as an academic exercise, because in this context it's pointless. In fact, those two lines can be replaced by simply assigning HighLowToggle to HIGH. You need a persistent variable, like a static or global.

yes just trying to learn how to use this by refactoring some messy code. I hear to stay away from Globals, so am trying to avoid learning bad habits.
95  Using Arduino / Programming Questions / ternary operator using HIGH and LOW on: March 03, 2013, 10:15:16 pm
trying to learn how to use ternary operators to refactor some code, but having some issues. This code lights up all the LEDs but they wont go low after they go high. It should light them all up one by one, then turn them all off a few times. Any ideas where I am going wrong?

Code:
void cycleLEDs(){
  const int setupLedSpeed = 80;
  
  boolean isHighLow = HIGH;
  boolean HighLowToggle = (isHighLow == HIGH)? HIGH : LOW;
 
  for(int i = 0; i < 10; i++){
    digitalWrite(LEDone, HighLowToggle);
    delay(setupLedSpeed);
    digitalWrite(LEDtwo, HighLowToggle);
    delay(setupLedSpeed);
    digitalWrite(LEDthree, HighLowToggle);
    delay(setupLedSpeed);
  }
}
96  Using Arduino / Microcontrollers / Re: SoftwareSerial with ATTiny84 using ATtiny library on: March 02, 2013, 12:36:13 pm



Quote
ok this is where I am confused. I have the capacitive sensor hooked up to the attiny not the arduino

So do I   smiley-grin

Quote
nor did I know it even had it.

It does, see the picture above

Quote
you say "using 0 and 1 you are interferring with MISO" I don't see how that will interfere with MISO on attiny...?

Look at the picture PB1 (or 1) is MISO used by TinyISP to communicate with your Arduino

Quote
I have capacitive sensor on 0 and 1 of attiny

Again 1 is MISO

Quote
and reading serial from attiny on PB3 (I thought this was default, I have always used this and it used to work fine)

No, the default is PB1 when you are using TinyISP.


If you use TinyDebugSerial, the default is PB3


Ohhhh, I was confusing myself because I was using a different core last time. it definitely had a different pin, i made suggestions you made and all is well. thanks for your patience smiley everything is working as expected. so using TinyISP is 0 the serial in( like Rx on arduino)? this relationship kind of confuses me because I have output from attiny going into Tx of arduino, which I thought was transmit. I would expect it to go into Rx.
97  Using Arduino / Microcontrollers / Re: SoftwareSerial with ATTiny84 using ATtiny library on: February 28, 2013, 03:43:14 pm
I am confused too.
I think it would be a good idea if you describe your project in more detail. It is unclear how many and which pins you are expecting to use and for what purpose.

Just to be clear that we are talking about the same:

The Capacitive Sensing Library ned a sense and receive pin
http://playground.arduino.cc//Main/CapacitiveSensor?from=Main.CapSense

If you are using TinyISP and knockbang , the serial output form attiny is pin PB1 (physical pin 6) connected to pin pin 12 on the UNO,
This is also the reason why you should not use this pin as sense pin, as I tryed to explain

That leaves you with 2 pins (three if you use the reset pin)





ok this is where I am confused. I have the capacitive sensor hooked up to the attiny not the arduino (maybe that is where the confusion is). you say "using 0 and 1 you are interferring with MISO" I don't see how that will interfere with MISO on attiny...? nor did I know it even had it.

Those sketches I have up there are both uploaded to the attiny, I have capacitive sensor on 0 and 1 of attiny. and reading serial from attiny on PB3 (I thought this was default, I have always used this and it used to work fine) going into Tx of arduino. But I also leave it plugged into the programming board, but not sure if this will cause any unexpected errors.

let me know if this clears it up or if its still confusing.
98  Using Arduino / Microcontrollers / Re: attiny IR communication library on: February 27, 2013, 08:29:19 pm
these both look cool, however I was looking more for communication that would let me send say, a string or int across arduinos via IR
99  Using Arduino / Microcontrollers / Re: SoftwareSerial with ATTiny84 using ATtiny library on: February 27, 2013, 06:59:17 pm
Ohh, my copy/paste technique was bad.

What I really meant was; Try moving the sense pins to PB3 and PB4.

Code:
CapacitiveSensor cs_4_2 = CapacitiveSensor(PB3,PB4);   

If you are using 0 and 1 you are interferring with MISO, which is used by KnockBang, and gives the weird results and errors.

I tried your sketch wirth this change and the output is OK.

I don't understand how it uses both. Eventually I will need those pins is possible to change it over to a different pin? (possibly just one...?)

and if I use your setup, I don't get what pin is the serial pin either. I always thought pin 2 was the send pin.

Also, this is REALLY confusing me now. When I unplug the serial read pin, it seems to be still reading serial... This is even with the basic example I posted above. it's usually plugged into pin 1 of the arduino board, but I break the connection all together and it still is printing to serial monitor.

I am keeping all the connections connected because its on a prototype board that sits on top of the arduino, not sure if that will matter. Its basically this board http://www.instructables.com/id/ATtiny-Programming-Shield-for-Arduino-1/ but with addition of a jumper going from Tx (pin1) on arduino to pin3 (PB2) on attiny
100  Using Arduino / Microcontrollers / attiny IR communication library on: February 26, 2013, 10:35:08 pm
are there any libraries to communicate between 2 attiny via IR? don't want to reinvent the wheel if its out there.
101  Using Arduino / Microcontrollers / Re: SoftwareSerial with ATTiny84 using ATtiny library on: February 26, 2013, 08:10:38 pm
Hmm, you are using the MOSI and MISO lines (0 and 1) as you sense pins.

Code:
CapacitiveSensor cs_4_2 = CapacitiveSensor(1,0);   

Try this instead, works for me (I think, atleast I don't get knock bang errors)

Code:
CapacitiveSensor cs_4_2 = CapacitiveSensor(1,0);   





oh doh! is it this line: #define KNOCK_BANG 1 because that was new on this round of sketches. I thought default was pin 3 (PCB3)? What weirds me out is this works on the first sketch I show above...? I can read the serial fine via pin 3, but its second sketch that fails.

I did try some tests to change it to #define KNOCK_BANG 3 and it seems like the same problem.
102  Using Arduino / Microcontrollers / Re: SoftwareSerial with ATTiny84 using ATtiny library on: February 26, 2013, 09:01:03 am
hilukasz
One thing to try:
Ensure that the MISO connection wire is as short (and fat) as possible:

http://arduino.cc/forum/index.php/topic,123388.msg1029246.html#msg1029246
(reply #74)

Quote
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85

This is jusr a warning, just ignore it.



thanks for suggestion. However, one I have now is very short and as large gauge as will fit in the pins smiley-sad

I'm wondering if it is something in my code conflicting with this type of serial read? It's strange that a simple example would work, and not my more complex one.

also as I am learning to get all this right (hopefully eventually smiley I am trying to document it for the UNO as I go here: http://hellowoo.com/hardware/serial-monitor-with-attiny85-and-arduino/
103  Using Arduino / Microcontrollers / Re: SoftwareSerial with ATTiny84 using ATtiny library on: February 25, 2013, 11:33:53 pm
ok great, now I try a more complex one and everything falls apart. for some reason it is storing program from last upload...?

Any upload errors?

Quote
I do stop the serial monitor before uploading, not sure if that matters.

Shouldn't matter.  The TinyISP sketch is coded to jump to the ISP part automatically.


just the standard:

Code:
Binary sketch size: 3,044 bytes (of a 8,192 byte maximum)
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85

get this with all attiny uploads though.
104  Using Arduino / Microcontrollers / Re: SoftwareSerial with ATTiny84 using ATtiny library on: February 25, 2013, 10:36:51 pm
ah, must have ended up messing with that one instead last time. wrote it down this time smiley

Ok the basic examples seem to work fine, for most part..

sketch:
Code:
#define KNOCK_BANG 1
#include <TinyDebugKnockBang.h>
 
#ifdef KNOCK_BANG
#define Serial Debug
#endif
int a;
void setup() {
    Serial.begin( 9600 );
        a = 1;
}
 
void loop() {
    delay(1000);
    Serial.println("hello world"); // debug output
    Serial.println(a); // debug output
    a++;
}


this is the output, though for some reason I always have to send "!" twice for it to work:
Code:
ΓΏ //this shows up without me typing "!"
--- Monitor starting ---

--- Knock-Bang fault: 11 ---
hello world
6
hello world
7
hello world
8
hello world
9

ok great, now I try a more complex one and everything falls apart. for some reason it is storing program from last upload...? I do stop the serial monitor before uploading, not sure if that matters.

the sketch:
Code:
#include <CapacitiveSensor.h>
#include <RunningMedian.h>
#define KNOCK_BANG 1
#include <TinyDebugKnockBang.h>
#ifdef KNOCK_BANG
#define Serial Debug
#endif

CapacitiveSensor cs_4_2 = CapacitiveSensor(1,0);        // 10 megohm resistor between pins 1 & 0, pin 0 is sensor pin, add wire, foil
const int sampleAmount = 5;
long runningAverage[sampleAmount];
boolean toggleLED;
int var;
    
boolean handIsPresent;    
void setup(){
   Serial.begin(9600);
   cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
   pinMode(2, OUTPUT);
   pinMode(1, OUTPUT);
   pinMode(0, INPUT);
   var = 0;
   handIsPresent = false;  
}
void loop(){
   //findCurrentHighestAverage
   checkIfHandIsPresent();
   if(handIsPresent){
     toggleTheLED();
   }
   delay(10);
   Serial.print("test");
}

void toggleTheLED(){
       if(toggleLED == 0){
         digitalWrite(2, LOW);
         toggleLED = 1;
         //delay(2000);
         return;
       } else if(toggleLED == 1) {
          digitalWrite(2, HIGH);
          toggleLED = 0;
          //delay(2000);
       }
}

////////////////
// Check if hand is present
//--------------

int lastReading;

void checkIfHandIsPresent(){
  const int threshold = 300;
  int currentReading = getAverage();

  Serial.print(currentReading-lastReading);
  Serial.print("\n");
  // this will always only read when
  if((currentReading-lastReading) > threshold){
    handIsPresent = true;
  } else { handIsPresent = false; }
  lastReading = currentReading;
}

////////////////
// get average reading out of X samples
//--------------
int getAverage() {
   int tempAverage = 0;
   int capacitiveAverage = 0;
   for(int i = 0; i < sampleAmount; i++){
    runningAverage[i] = cs_4_2.capacitiveSensor(30);
   }
   // add all the samples up
   for(int i = 0; i < sampleAmount; i++){
     tempAverage = runningAverage[i] + tempAverage;
   }
   // divide by number of samples to get average
   capacitiveAverage =  tempAverage/sampleAmount;
   //printSampleData(capacitiveAverage);
   return capacitiveAverage;
}

Code:
73
hello world
74
hello world
75
hello world
76
hello world
77
hello world
78
hello world
79

--- Knock-Bang fault: 11 ---

--- Knock-Bang fault: 11 ---

--- Knock-Bang fault: 11 ---

--- Knock-Bang fault: 4 ---

--- Knock-Bang fault: 11 ---

--- Knock-Bang fault: 11 ---

--- Knock-Bang fault: 11 ---

--- Knock-Bang fault: 11 ---

73
hello world
74
hello world
75
hello world
76
hello world
77
hello world
78
hello worl
--- Knock-Bang fault: 11 ---

--- Knock-Bang fault: 11 ---

--- Knock-Bang fault: 4 ---

105  Using Arduino / Microcontrollers / Re: SoftwareSerial with ATTiny84 using ATtiny library on: February 24, 2013, 06:28:24 pm

Sorry about that.  Try it now.

did that file get revered maybe? I formatted and had to download it again and that file seems to be missing again.
Pages: 1 ... 5 6 [7] 8 9 ... 13