Show Posts
Pages: [1] 2 3 ... 15
1  Using Arduino / Microcontrollers / Re: Arduino Pro Mini, ATtiny45 and V-USB on: March 24, 2014, 01:47:26 pm
I see. I'll have to study V-USB some more then.
2  Using Arduino / Microcontrollers / Re: Arduino Pro Mini, ATtiny45 and V-USB on: March 24, 2014, 10:58:07 am
I was actually talking about single chip (ATmega328 + USB connector) in last post.

Oh, I see.

Using RX/TX seems like a bad idea on a mega328. You won't be able to use the serial port if you do that.

No, no...

Maybe I wasn't clear. Or maybe I'm missing something. We are considering this setup:

Arduino Pro Mini loaded with V-USB MIDI firmware. With that, Arduino is processing different inputs. Now, in order to actually connect Arduino with USB connector, should I directly connect RX/TX pins to D+/D- pins or?
3  Using Arduino / Microcontrollers / Re: Arduino Pro Mini, ATtiny45 and V-USB on: March 24, 2014, 09:18:29 am
The mega328 RX/TX would NOT connect to directly any of the USB pins.

The Tiny45 chip acts as an interface between mega328 and USB. I'm guessing the mega328 RX/TX would connect to pins 3 and 6 of the Tiny45 on that page.

I was actually talking about single chip (ATmega328 + USB connector) in last post.
4  Using Arduino / Microcontrollers / Re: Arduino Pro Mini, ATtiny45 and V-USB on: March 24, 2014, 06:58:45 am
I'm not sure how fast things would run.

"reading a bunch of pots and buttons" isn't much work, I suspect it will run OK.

There's no reason V-USB firmware would mess with UART stuff, they're completely separate in the chip.

But... if there's a ready-built MIDI-to-USB software for the Tiny45 then maybe that's the easiest way to do it. Do you have a link to that?


Sure: http://electronicsodyssey.blogspot.com/2011/10/atmel-attiny45-attiny85-based-usb-midi.html

So, if that would work, then I should just connect RX/TX to D+/D- on USB connector, correct? (on atmega328 that is)
5  Using Arduino / Microcontrollers / Re: Arduino Pro Mini, ATtiny45 and V-USB on: March 24, 2014, 05:44:46 am
Why do you need two devices? Why don't you do both things on the pro-mini?


Because I've read that V-USB requires much CPU use, so I'm not sure how fast things would run.
6  Using Arduino / Microcontrollers / Arduino Pro Mini, ATtiny45 and V-USB on: March 24, 2014, 04:59:14 am
There are two parts to setup I'd like to use:

1) Arduino Pro Mini reading a bunch of pots and buttons
2) ATtiny45 with MIDI V-USB firmware reading data from Pro Mini and sending it to PC. ATtiny must also be able to send data from PC to Arduinos RX pin

Now, I was reading about software and hardware UART and it seems like ATtiny45 doesn't have hardware UART. What I'm interested in, will hardware UART enabled ATtiny like 2313 or ATmega8/168/328 be able to read/send data from Arduino without coding it (just by plugging Arduinos RX/TX into ATtinys TX/RX) or V-USB firmware messes with UART stuff? Please note that both V-USB and UART are pretty new terms to me, so I don't understand it that well.
7  Using Arduino / Microcontrollers / AVR ISP MKII clones on: February 19, 2014, 07:39:42 am
I need a programmer to program ATmega328 and 8u2/16u2 chips, so I was looking on eBay for ISP MKII clones, like this one:

http://www.ebay.com/itm/USB-programmer-AVRISP-mkII-mk2-clone-ATMEL-AVR-Fit-51-Series-ATmega-PWM-ATtiny-/300939395901?pt=LH_DefaultDomain_0&hash=item461162c33d

So, are they reliable and worth the money?

EDIT:

Or something like this:
http://www.ebay.com/itm/USB-ISP-Programmer-for-ATMEL-AVR-51-ATMega-ATTiny-/200460739146
8  Using Arduino / Programming Questions / Re: Debouncing a potentiometer on: February 09, 2014, 12:03:31 pm
In between setMuxOutput and readPots functions is function which reads 4x5 button matrix and handles few LEDs, so I pressumed that time needed for that is enough to allow some settling of pins.

Wrong presumption. Time difference was less than 1 ms, so I added a new variable, uint32_t muxSettleTime, so now setMuxOutput looks like this:

Code:
void setMuxOutput() {
  
    if (!muxSettleTime) {

//reset the variable to 0 after its value reaches 8 using masking
    muxInput &= 7;
    
    //switch to next mux input
    PORTC = muxInput << 2;

muxSettleTime = millis();

}
 
}

And readPots() is also slighty modified:

Code:
void readPots() {

if ((millis() - muxSettleTime) > 3) {

muxSettleTime = 0;


....


...


muxInput++;

}

Due to 3 ms delay between seting pins and reading the values, I also removed the following check from potValueStable function:

Code:
&& ((millis() - analogueValueTimer) > ANALOGUE_TIMEOUT_MIN)

So far, the values aren't jumping but I'll play around with pots for some more time and report back here.
9  Using Arduino / Programming Questions / Re: Debouncing a potentiometer on: February 09, 2014, 11:02:47 am
What happens if you take a few readings and average them? 4 or 8 readings makes the averaging easier.

Is the impedance of the pot 10k or less?

I presume you know to allow a settling time when you change to reading a different pot.

...R

In between setMuxOutput and readPots functions is function which reads 4x5 button matrix and handles few LEDs, so I pressumed that time needed for that is enough to allow some settling of pins. The pots are 10k yes, linear. I haven't tried averaging the pots yet, I'll try.
10  Using Arduino / Programming Questions / Debouncing a potentiometer on: February 09, 2014, 10:34:15 am
Potentiometers in my project send MIDI data, therefore I need 7-bit resolution. Here is how my current debouncing algorithm works:

First I'm setting the active input on 4051 multiplexers on which potentiometers are connected:

Code:
void setMuxOutput() {
 
    //reset the variable to 0 after its value reaches 8 using masking
    muxInput &= 7;
   
    //switch to next mux input
    PORTC = muxInput << 2;
 
}

After that I'm reading the pots:

Code:
void readPots() {

    //check analogue inputs from 2 4051 analogue multiplexers
    for (int i=0; i<NUMBER_OF_MUX; i++) {

            //calculate pot number
            uint8_t potNumber = (i*8) + muxInput;

            //read analogue value from mux
    //we need 7-bit value for MIDI message
            int8_t tempValue = analogRead(analogueInputArray[i]) >> 3;

//if new reading is stable send new MIDI message
if (potValueStable(tempValue, lastAnalogueValue[potNumber], analogueValueTimer[potNumber])) {
//debugging
Serial.print("Pot number: ");
Serial.println(potNumber);
Serial.print("Value: ");
Serial.println(tempValue);
Serial.print("Current time: ");
Serial.println(millis());
Serial.println();

}

    }
     
      //increment mux input for next loop iteration
      muxInput++;
 
}

potValueStable is a function which returns true if pot value passes through a series of conditions:

Code:
potValueStable(int16_t currentValue, int16_t previousValue, uint32_t analogueValueTimer) {

//calculate difference between current and previous reading
int16_t analogueDiff = currentValue - previousValue;
if (analogueDiff < 0) analogueDiff *= -1;

/*
When value from pot hasn't changed for more than ANALOGUE_TIMEOUT_MAX value (time in ms), pot must
exceed FILTER_AMOUNT (2) value. If the value has changed during ANALOGUE_TIMEOUT_MAX, it must be
different from previous reading (analogueDiff > 0). If any condition is true, analogueValue timer
is updated. If there is some difference between the two readings and change occurred in less
than ANALOGUE_TIMEOUT_MIN ignore the reading.

*/

if

(

(analogueDiff >= ANALOGUE_THRESHOLD) ||

(

(analogueDiff > 0) &&
((millis() - analogueValueTimer) < ANALOGUE_TIMEOUT_MAX)
&& ((millis() - analogueValueTimer) > ANALOGUE_TIMEOUT_MIN)

)

)

{

//reset timer on each new value
analogueValueTimer = millis();
                 
//update previous pot value
previousValue = currentValue;

return true;

}

return false;

}

ANALOGUE_TIMEOUT_MAX is set to 200ms and ANALOGUE_TIMEOUT_MIN is set to 5ms.

So, this is how the regular readings look like:

Quote
Pot number: 8
Value: 73
Current time: 115934

Pot number: 8
Value: 74
Current time: 115944

Pot number: 8
Value: 75
Current time: 115960

Pot number: 8
Value: 76
Current time: 115979

Now I waited a couple of seconds and then continued to move the pot:

Quote
Pot number: 8
Value: 78
Current time: 118244

Pot number: 8
Value: 79
Current time: 118280

Pot number: 8
Value: 80
Current time: 118349

So, if you get stable reading from pot and then you don't move it for longer than ANALOGUE_TIMEOUT_MAX (200ms) the difference between last and current reading must be ANALOGUE_THRESHOLD, which is 2. All fine so far, but there is still a case when values start jumping and this is the part I'm struggling to solve (note that I moved the pot only first time, the rest of values were jumping without any touching of pot):

Quote
Pot number: 8
Value: 100
Current time: 190818

Pot number: 8
Value: 101
Current time: 190830

Pot number: 8
Value: 100
Current time: 190907

Pot number: 8
Value: 101
Current time: 190919

Pot number: 8
Value: 100
Current time: 190982

Pot number: 8
Value: 101
Current time: 190993

Pot number: 8
Value: 100
Current time: 191011

Time difference between those values is less than I defined with ANALOGUE_TIMEOUT_MAX and more than ANALOGUE_TIMEOUT_MIN, so they're right in the range when it's actually possible to move the pot at that speed.  So, what are your suggestions for this problem? I would appreciate any advice.
11  Using Arduino / Microcontrollers / Re: Altmustech AU-123 USB MIDI with Arduino on: February 09, 2014, 07:10:34 am
I use this chip in my MIDI controller project based on Arduino without any problems. It's very convenient to use.

Awesome! Do you connect RX/TX pins directly to it or are there other componentes involved (caps, optocouplers...)?
12  Using Arduino / Programming Questions / Re: Including interrupt routine in library on: February 04, 2014, 05:13:56 pm
And it doesn't work?

So what errors did you get?

No, I'm getting error that milliSeconds is not declared in this scope.
13  Using Arduino / Programming Questions / Including interrupt routine in library on: February 04, 2014, 11:33:57 am
I'm writing a library which sets up timer0 so that I can use my own implementation of millis() (note: I am not using Arduino code, only pure AVR C). Now, I've written a function which sets up timer and now I can't figure out how do I include ISR routine inside a library. The code I need in lib is this:

Code:
ISR(TIMER0_COMPA_vect)  {

//increment current time
milliSeconds++;

}

milliSeconds variable is declared as volatile uint32_t and code which accesses variable is this:

Code:
uint32_t OpenDeck::rTimeMillis() {

//variable to hold time in ms since sketch is running
uint32_t rTime;

//disable interrupts during access to milliSeconds
ATOMIC_BLOCK(ATOMIC_FORCEON) {

rTime = milliSeconds;

}

return rTime;

}
14  Using Arduino / Programming Questions / Re: Source code of Arduino functions - where to look? on: February 03, 2014, 12:14:59 pm

Thanks a lot! I thought set/cli were Arduino specific functions. I only needed to add
Code:
#include <avr/interrupt.h>
to my code.
15  Using Arduino / Programming Questions / Source code of Arduino functions - where to look? on: February 03, 2014, 11:41:06 am
Specifically, I'm trying to find source code for these Arduino functions:

micros/millis
sei/cli

Thanks!
Pages: [1] 2 3 ... 15