Show Posts
Pages: [1] 2 3 ... 17
1  Using Arduino / Programming Questions / Re: Inheritance, virtual function... or something? on: August 10, 2014, 01:50:56 pm
Virtual functions sounded good to me until I found out (well, that is at least what all the examples I've found are showing) their use is when you want to create a derived class from your base class. I don't want to do that. I only have one class.
2  Using Arduino / Programming Questions / Inheritance, virtual function... or something? on: August 10, 2014, 05:32:44 am
I've written a fairly big library which deals with potentiometers, buttons, LEDs, MIDI etc. Now, there is a part of that library which deals directly with hardware. I've managed to "separate" that part from library and I've put the hardware control functions within my main.cpp (I'm not using any Arduino libs). Here's how it works:

This is a function which switches columns in a matrix (in my library):

Code:
void OpenDeck::nextColumn()   {

sendLEDrowsOffCallback();

if (column == _numberOfColumns) column = 0;

sendColumnSwitchCallback(column);

//increment column
column++;

}

So, before switching to another column, it first turns off all LED rows off, and then activates next column. So, where are those functions? Within my main.cpp. I've used callbacks to handle this:

Code:
openDeck.setHandleColumnSwitch(activateColumn);
openDeck.setHandleLEDrowsOff(ledRowsOff);

...
...
...

//switch to next matrix column
void activateColumn(uint8_t column)  {

//column switching is controlled by 74HC238 decoder
PORTC &= 0b11000111;
PORTC |= (0b11000111 | (column << 3));

}

//control select pins on mux
void setMuxOutput(uint8_t muxInput) {

PORTC &= 0b11111000;
PORTC |= muxInput;

}

There are way more functions dealing with hardware, but this should be enough for an example. So, while this works, I find it be a bit tedious: I have to set callback handler, implement it, and also write a chunk of code within my library to make that stuff work. Is there a better way for achieving this? I remember when we coded in Java on college couple of years ago, I don't remember how was it called, but you could define a function in your library with a certain keyword, and any time you made an object in your main program, you had to implement that function. Is something like that possible in AVR C?
3  Using Arduino / Microcontrollers / Re: Pro Mini programming with USBasp on: July 31, 2014, 01:50:33 pm
Ah, I see, thanks. What does that "cannot set SCK period" error even measn then? Because I can upload new firmware on chip just fine. Also, how can I check fuse settings with avrdude? It lists all three as 0.
4  Using Arduino / Microcontrollers / Pro Mini programming with USBasp on: July 31, 2014, 12:11:45 pm
I'm not really sure if this is intended behavior, or something is wrong. I've tried to program Arduino Pro Mini using USBasp programmer I bought from eBay. Every connection is okay. As soon as I connect USBasp to USB (and Pro Mini is attached to USBasp), LED on pin 13 on Pro Mini starts blinking really, really fast. Do note that I can program the chip with no issues. I've uploaded basic blink sketch to Pro Mini using USBasp, but LED 13 is blinking really fast, so nothing changed. Then I tried to unplug Pro Mini from USBasp, and tried to power it using only +5V and GND connections, and LED was blinking like in sketch I've uploaded, meaning that code is running just fine. I don't know why the LED blinks all the time insanely fast while Pro Mini is connected to USBasp. Here's output from avrdude:

Code:
D:\Applications\AVRdude>avrdude.exe -c usbasp -v -v -pm328p -u -U flash:w:Blink.
hex

avrdude.exe: Version 6.1, compiled on Mar 13 2014 at 00:09:49
             Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
             Copyright (c) 2007-2014 Joerg Wunsch

             System wide configuration file is "D:\Applications\AVRdude\avrdude.
conf"

             Using Port                    : usb
             Using Programmer              : usbasp
avrdude.exe: seen device from vendor ->www.fischl.de<-
avrdude.exe: seen product ->USBasp<-
             AVR Part                      : ATmega328P
             Chip Erase delay              : 9000 us
             PAGEL                         : PD7
             BS2                           : PC2
             RESET disposition             : dedicated
             RETRY pulse                   : SCK
             serial program mode           : yes
             parallel program mode         : yes
             Timeout                       : 200
             StabDelay                     : 100
             CmdexeDelay                   : 25
             SyncLoops                     : 32
             ByteDelay                     : 0
             PollIndex                     : 3
             PollValue                     : 0x53
             Memory Detail                 :

                                      Block Poll               Page
          Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW
 MaxW   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ -----
 ----- ---------
               eeprom        65    20     4    0 no       1024    4      0  3600
  3600 0xff 0xff
               flash         65     6   128    0 yes     32768  128    256  4500
  4500 0xff 0xff
               lfuse          0     0     0    0 no          1    0      0  4500
  4500 0x00 0x00
               hfuse          0     0     0    0 no          1    0      0  4500
  4500 0x00 0x00
               efuse          0     0     0    0 no          1    0      0  4500
  4500 0x00 0x00
               lock           0     0     0    0 no          1    0      0  4500
  4500 0x00 0x00
               calibration    0     0     0    0 no          1    0      0     0
     0 0x00 0x00
               signature      0     0     0    0 no          3    0      0     0
     0 0x00 0x00

             Programmer Type : usbasp
             Description     : USBasp, http://www.fischl.de/usbasp/

avrdude.exe: auto set sck period (because given equals null)
avrdude.exe: warning: cannot set sck period. please check for usbasp firmware up
date.
avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.05s

avrdude.exe: Device signature = 0x1e950f
avrdude.exe: NOTE: "flash" memory has been specified, an erase cycle will be per
formed
             To disable this feature, specify the -D option.
avrdude.exe: erasing chip
avrdude.exe: auto set sck period (because given equals null)
avrdude.exe: warning: cannot set sck period. please check for usbasp firmware up
date.
avrdude.exe: reading input file "Blink.hex"
avrdude.exe: input file Blink.hex auto detected as Intel Hex
avrdude.exe: writing flash (180 bytes):

Writing | ################################################## | 100% 0.17s

avrdude.exe: 180 bytes of flash written
avrdude.exe: verifying flash memory against Blink.hex:
avrdude.exe: load data flash data from input file Blink.hex:
avrdude.exe: input file Blink.hex auto detected as Intel Hex
avrdude.exe: input file Blink.hex contains 180 bytes
avrdude.exe: reading on-chip flash data:

Reading | ################################################## | 100% 0.16s

avrdude.exe: verifying ...
avrdude.exe: 180 bytes of flash verified

avrdude.exe done.  Thank you.
5  Using Arduino / General Electronics / Re: 2n2222 Inverter circuit on: June 25, 2014, 08:32:10 am
I connected the AVR RX pin to wrong place, ugh. Working now! With NAND solution I simply connected one input of gate to +5V, and the other was TX pin from MIDI chip. USART RX pin was connected to NAND gate output.
6  Using Arduino / General Electronics / 2n2222 Inverter circuit on: June 25, 2014, 08:11:19 am
I've got USB MIDI chip, TTL compatible, which connects to USART pins on Arduino. Sending MIDI data from Arduino to that chip (which in turns sends received data to PC via USB) works without any additionalo circutry. However, MIDI Out on that MIDI chip is marked as active high, while AVR USART pins are active low, therefore, in  order to send data to Arduino via that chip, I need some kind of inverter. Official documentation for that chip recommends 7400 NAND gates. I've tried that and it works without any issues. However, given that 7400 is a 16-pin DIP with 4 NAND gates, most of that chip is left unused, so I figured I could use 2N2222 transistor as inverter circuit. Since I know virtually nothing about transistors, I have no idea how am I supposed to connect. it. I found this circuit somewhere on internet, however that didn't work (RX LED on Arduino isn't flashing at all). I'm guessing I should change the resistor values to something else, any advice?

7  Using Arduino / Microcontrollers / Re: Pro Mini, USB MIDI chip and sending and receiving MIDI on: June 20, 2014, 07:36:23 pm
Okay so, datasheet says for MIDI out that is an "active high" pin. Can someone please explain what does that mean? Does that require connecting the pin to +5V or some other thing?
8  Using Arduino / Microcontrollers / Pro Mini, USB MIDI chip and sending and receiving MIDI on: June 20, 2014, 02:45:55 pm
I built a MIDI controller based on Arduino Pro Mini. Everything works fine, and so far, I've used the serial conversion to MIDI. Both sending and receiving the MIDI works as expected. To explain the previous setup a bit more:

1) Pro Mini is connected to PC via CP2102 module
2) I convert serial messages from Arduino with hairless-midi application
3) I route converted messages to my MIDI software via virtual MIDI cable (loopBe30)

Everything works fine. Therefore, I ordered a USB MIDI chip, more specifically, Altmustech AU-123. I've designed a PCB for it. Datasheet (attached) says it's TTL compatible, so, only change I did in my code was to change the serial baud rate from 38400 to standard MIDI speed, 31250. I've connected RX/TX pins directly to that chip, and my PC recognizes the device as USB MIDI. A good start. Sending MIDI data from Arduino to PC via that chip works perfectly fine, however, receiving does not. It's as if the messages sent to that chip are somehow inverted, except they're not. For instance, sending MIDI note 0 on channel 1 with 127 velocity should result in following message:

144 0 127

However, on Arduino end I'm receiving this:

243 1 0

I can't find any sense in that. Any suggestions? Note that my code for this test consists merely of this:

Code:
void loop() {

if (Serial.available() > 0) Serial.write(Serial.read());

}

If I go back to previous method, 38400 baud rate with serial-to-midi conversion, I receive the expected input on Arduino end.
9  Community / Exhibition / Gallery / Anandamidi MIDI controller on: June 04, 2014, 11:26:36 am
New MIDI controller from me. 16 buttons, 6 pots, 3 faders and 10 LEDs.

Hardware base:
Arduino Pro Mini
4051 multiplexer
button/LED matrix

Software base:
Ownduino (my own minimal implementation of some Arduino functions)
MIDI library 3.2 (with some modifications to make it more minimal)
OpenDeck library (my own matrix/pot/mux library)

Very happy about this project, I still have some minor work around the case but this is mostly it.
Source is freely available here: https://github.com/paradajz/Tannin (source is based on that controller, it's 95% the same)

Pictures:



















And here's a tryout video:

https://www.youtube.com/watch?v=B0tTqctuLCI

EDIT:
Way more details about the project on my blog:
https://shanteacontrols.wordpress.com/
10  Using Arduino / Project Guidance / Re: Choosing correct microcontroller for the job on: May 29, 2014, 02:51:05 am
Sure.

Thanks! Awesome approach. However, doesn't that interrupt line require debouncing?
11  Using Arduino / Project Guidance / Re: Choosing correct microcontroller for the job on: May 28, 2014, 04:21:25 pm
I don't know if there is a shift register that outputs a low if any input is clocked in as a low. That's why I suggested the diodes in a Wired AND configuration - any button low creates an interrupt, the interrrupt pulses the latch line, and you have the input high/low states captured.

Can you draw a schematic with one chip in that configuration? I'm still having difficulties with understanding the setup.
12  Using Arduino / Project Guidance / Re: Choosing correct microcontroller for the job on: May 28, 2014, 12:51:22 pm
RGB LED is 3 LEDs in one package.
Thus 102 RGB LEDs is really 306 LEDs. You can see that on any datasheet.

Ah, I see. Thanks.

I would use 13 shift-in registers with pullup resistors and  buttons that Gnd a pin when pressed.  Scan all inputs in frequently and look for 0s to act upon (10 times a second? 25 times a second?) Or use 102 diodes with cathode on each pin and common anodes, use the anode as an interrupt and scan when an interrupt comes in. Read in the 13 bytes using SPI.transfer at 8 MHz transfer rate, can shift them into an array in about 13uS, then scan the array for 0s to act on.
Might be I2C expansion shield that can do that also, but at slower speed (100KHz or 400KHz transfer rate).  How responsive do you want it?

Interrupt driven shift register? Which register is capable of that? Responsive, well, instantly? Since it's supposed to be Ableton Live controller, you need "instant" (in human terms, not microcontroller) reaction.
13  Using Arduino / Project Guidance / Re: Choosing correct microcontroller for the job on: May 28, 2014, 12:20:38 pm
You're gonna need more external hardware than you think.
102 RGB LEDs is like controlling 306 LEDs.

Euh, what? Care to explain?

102 pushbuttons, can arrange as a 10x11 keypad as long as only 1 will be pushed at a time. keypad.h library.

No, I need multiple presses.
14  Using Arduino / Project Guidance / Re: Choosing correct microcontroller for the job on: May 28, 2014, 09:39:34 am
It entirely depends on what you want to do with it.
you've only said what input/output you have, but not what your processing needs are. If you just want to get the values of all those things via serial communication, and be able to set the values of those leds also via serial communication, even the most basic microcontroller would probably suffice (unless you want extremely fast update rates).

If you want to have realtime control over those leds with the buttons & potentiometers as inputs with all kinds of special patterns, memory/cpu intensive processes, ... then you'll needs one of the more powerfull versions.

Ah yeah, sorry. The use would be within MIDI controller. I also want to control LED brightness/colors... Now that I think of it, two MAX7219 chips would probably be best solution for LEDs. Controller needs to both send and receive serial.
15  Using Arduino / Project Guidance / Choosing correct microcontroller for the job on: May 28, 2014, 09:29:13 am
I need advice on choosing the correct microcontroller for this kind of setup:

102 pushbuttons
102 RGB LEDs
44 potentiometers
5 rotary encoders

Multiplexing (matrices) is the obvious choice for that many buttons/LEDs. I was thinking about 2 8x8 matrices for that part. (shared columns on buttons/LEDs). Two ULN sinks, two shift registers for button inputs (4021 or something better/faster? but not very expensive) and two LED drivers (which ones?). Each ULN would be connected to a decoder, and those two decoders would then have their select pins chained. Correct approach? Shift registers for buttons would have clock and latch pins chained as well (correct?). So, 3 pins to shift through 16 columns and 4 for 16 rows of buttons. Not sure about the LED driver part. For potentiometers, I was planning on using 6 MPC3208 chips via SPI. Rotary encoders... Don't know which components to chose for that job.

So, which microcontroller do you suggest? ATmega1284? Is that enough power to drive all that without too much delay? Or should I choose ARM for this?
Pages: [1] 2 3 ... 17