Show Posts
Pages: [1] 2
1  Using Arduino / Audio / Re: MIDI - UNO Worked, Leonardo and DUE not work, Why? on: August 17, 2014, 01:56:09 pm
Hi,

You have to modify  MIDI.h to get it work with Leonardo variant boards.

Check the link below and apply the steps explain in the last message.

http://forum.arduino.cc/index.php?topic=143704.msg1592752#msg1592752

/Den├Ąz
2  Topics / Home Automation and Networked Objects / Re: Arduino Jquery retain sliders last value on: August 10, 2014, 05:31:43 am
Thanks for the clue. I think setting up a cookie is also a solution. The problem is I have a very limited knowledge of jquery and html. I really dont know how to embed these into the arduino sketch. I would really appreciate if you could give me code examples. I was looking for a sample to play with but couldnot finy any.
3  Topics / Home Automation and Networked Objects / Arduino Jquery retain sliders last value on: August 09, 2014, 12:19:16 pm
Hello,

I am trying to create a html page for basic home automation.

I do not know anything about hmtl and javascript. But I managed to finish the audio control page by modifiying one of the sample skecthes. Now, I have one single problem.

Each time I refresh the page or load it from an other device the sliders goes back to the default value "0".

Is it possible to retain the last value for the sliders or buttons and load the page with last known value?

Code:
 
  #include "SPI.h"
  #include "Ethernet.h"
  #include "WebServer.h"
  #include <Wire.h>
  #include <TDA7439.h>
  TDA7439 equ;

  static uint8_t mac[6] = { 0x02, 0xAA, 0xBB, 0xCC, 0x00, 0x22 };
  static uint8_t ip[4] = { 192, 168, 0, 100 };
 
  #define PREFIX "/rgb"
  WebServer webserver(PREFIX, 80);
 
  int input1v; 
  int input2v;
  int input3v;
  int input4v;
  int volume;
  int inputt;
  int inputm;
  int inputb;
  int input = 1;
 
  void rgbCmd(WebServer &server, WebServer::ConnectionType type, char *, bool)
  {
    if (type == WebServer::POST)
    {
      bool repeat;
      char name[16], value[16];
      do
      {
        repeat = server.readPOSTparam(name, 16, value, 16);
 
        if (strcmp(name, "input1v") == 0)
        {
          if(input1v > 0){selectInput(1);}
          input1v = strtoul(value, NULL, 10);
          volume = input1v;
        }

        if (strcmp(name, "inputt") == 0)
        {
          inputt = strtoul(value, NULL, 10);
        }
       
        if (strcmp(name, "inputm") == 0)
        {
          inputm = strtoul(value, NULL, 10);
        }
       
        if (strcmp(name, "inputb") == 0)
        {
          inputb = strtoul(value, NULL, 10);
        }
       
        if (strcmp(name, "input2v") == 0)
        {
          if(input2v > 0){selectInput(2);}
          input2v = strtoul(value, NULL, 10);
          volume = input2v;
        }
       
        if (strcmp(name, "input3v") == 0)
        {
          if(input3v > 0){selectInput(3);}
          input3v = strtoul(value, NULL, 10);
          volume = input3v;
        }
       
        if (strcmp(name, "input4v") == 0)
        {
          if(input4v > 0){selectInput(4);}
          input4v = strtoul(value, NULL, 10);
          volume = input4v;
        }

      } while (repeat);
     

      server.httpSeeOther(PREFIX);

 
      return;
    }
 
    server.httpSuccess();

    if (type == WebServer::GET)
    {
      P(message) =
    "<!DOCTYPE html><html><head>"
    "<meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1\">"
    "<title>Home Automation</title>"
    "<link rel=\"stylesheet\" href=\"http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css\" />"
    "<script src=\"http://code.jquery.com/jquery-2.1.1.min.js\"></script>"
    "<script src=\"http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js\"></script>"
   
    "<script>"
    "$(document).ready(function(){ $('#input1v, #inputt, #inputm, #inputb, #input2v, #input3v, #input4v').slider;"
    "$('#input1v, #inputt, #inputm, #inputb, #input2v, #input3v, #input4v').bind( 'change', function(event, ui) { jQuery.ajaxSetup({timeout: 100});"
    "var id = $(this).attr('id'); var strength = $(this).val();"
    "if (id == 'input1v') $.post('/rgb', { input1v: strength } );"
    "if (id == 'inputt') $.post('/rgb', { inputt: strength } );"
    "if (id == 'inputm') $.post('/rgb', { inputm: strength } );"
    "if (id == 'inputb') $.post('/rgb', { inputb: strength } );"
    "if (id == 'input2v') $.post('/rgb', { input2v: strength } );"
    "if (id == 'input3v') $.post('/rgb', { input3v: strength } );"
    "if (id == 'input4v') $.post('/rgb', { input4v: strength } ); });});"
    "</script>"
   
    "</head>"
    "<body>"
   
"<div data-role=\"page\" data-control-title=\"Volume\" id=\"page1\">"
    "<div data-role=\"header\" data-position=\"fixed\">"
        "<div data-controltype=\"textblock\">"
            "<p style=\"text-align: center;\">"
                "Audio Mixer Volume Controller"
            "</p>"
        "</div>"
   "</div>"
   
"<div data-role=\"content\">"

       
        "<div data-role=\"fieldcontain\" data-controltype=\"slider\">"
            "<label for=\"input4v\">"
                "Airplay"
            "</label>"
            "<input id=\"input4v\" type=\"range\" name=\"slider\" value=\"0\" min=\"0\" max=\"48\" data-highlight=\"true\">"
        "</div>"       
       
       
        "<div data-role=\"fieldcontain\" data-controltype=\"slider\">"
            "<label for=\"input3v\">"
                "Channel 2"
            "</label>"
            "<input id=\"input3v\" type=\"range\" name=\"slider\" value=\"0\" min=\"0\" max=\"48\" data-highlight=\"true\">"
        "</div>"       
       
           
        "<div data-role=\"fieldcontain\" data-controltype=\"slider\">"
            "<label for=\"input2v\">"
                "Channel 3"
            "</label>"
            "<input id=\"input2v\" type=\"range\" name=\"slider\" value=\"0\" min=\"0\" max=\"48\" data-highlight=\"true\">"             
        "</div>"


           
            "<div data-role=\"collapsible-set\">"
            "<div data-role=\"collapsible\">"
                "<h3>"
                    "EQ"
                "</h3>"
                "<div data-role=\"fieldcontain\" data-controltype=\"slider\">"
                    "<label for=\"inputt\">"
                        "Treble"
                    "</label>"
                    "<input id=\"inputt\" type=\"range\" name=\"slider\" value=\"7\" min=\"0\" max=\"14\" data-highlight=\"false\">"
                "</div>"
                "<div data-role=\"fieldcontain\" data-controltype=\"slider\">"
                    "<label for=\"inputm\">"
                        "Mid"
                    "</label>"
                    "<input id=\"inputm\" type=\"range\" name=\"slider\" value=\"7\" min=\"0\" max=\"14\" data-highlight=\"false\">"
                "</div>"
                "<div data-role=\"fieldcontain\" data-controltype=\"slider\">"
                    "<label for=\"inputb\">"
                        "Bass"
                    "</label>"
                    "<input id=\"inputb\" type=\"range\" name=\"slider\" value=\"7\" min=\"0\" max=\"14\" data-highlight=\"false\">"
                "</div>"
            "</div>"
            "</div>"
   
    "<div data-role=\"footer\" data-position=\"fixed\">"
    "<div data-role=\"navbar\" data-iconpos=\"top\"  data-position=\"fixed\">"
        "<ul>"
            "<li>"
                "<a href=\"#page1\" data-transition=\"slide\"  data-icon=\"audio\">Audio</a>"
            "</li>"
            "<li>"
                "<a href=\"#page2\" data-transition=\"slide\"  data-icon=\"info\">Lights</a>"
            "</li>"
       "</ul>"
    "</div>"
    "</div>"
   
"</div>"
"</div>"   
     
 "<div data-role=\"page\" id=\"page2\">"
     "<div data-role=\"header\" data-position=\"fixed\">"
        "<div data-controltype=\"textblock\">"
            "<p style=\"text-align: center;\">"
                "Light Power Socket Remote"
            "</p>"
        "</div>"
   "</div>"
   
  "<div data-role=\"content\"></div>"
  "<div data-role=\"footer\" data-position=\"fixed\">"
  "<div data-role=\"navbar\" data-iconpos=\"top\" data-position=\"fixed\">"
            "<ul>"
                "<li>"
                    "<a href=\"#page1\" data-transition=\"slide\" data-icon=\"audio\">Audio</a>"
                "</li>"
                "<li>"
                    "<a href=\"#page2\" data-transition=\"slide\" data-icon=\"info\">Lights</a>"
                "</li>"
            "</ul>"
        "</div>"
  "</div>"
"</div> "         
     
     
     
    "</body>"
  "</html>";
 
      server.printP(message);
    }
  }
 
  void setup()
  {
 
    Serial.begin(9600);
    Wire.begin();
 
    // setup the Ehternet library to talk to the Wiznet board
    Ethernet.begin(mac, ip);
    webserver.setDefaultCommand(&rgbCmd);
 

     webserver.begin();
     equ.setInput(input);
     equ.inputGain(0);
     equ.setVolume(0);
     equ.setSnd(0,1);
     equ.setSnd(0,2);
     equ.setSnd(0,3);
     equ.spkAtt(0);
  }
 
  void loop()
   {
    webserver.processConnection();
    equ.setSnd(inputb-7,1); //bass
    equ.setSnd(inputm-7,2); //mid
    equ.setSnd(inputt-7,3);//treble
    equ.setVolume(volume);

  }
 
  void selectInput(int x)
   {
     if ( input == x) {}
     else{input = x; equ.setInput(input);}
   }
 
   
4  Using Arduino / LEDs and Multiplexing / Re: 32X8 Led display multizone problem, with Parola Library on: April 27, 2014, 01:42:58 am
You are great Marco, thank you so much for your help and for the example sketch.

All problems solved and my sketch size also went down to 54% from 90%.
5  Using Arduino / LEDs and Multiplexing / Re: 32X8 Led display multizone problem, with Parola Library on: April 26, 2014, 04:16:52 pm
Thank you so much for your reply Marco.

It was not finishing the setup(). I think it was freezing before P.begin() cause the buttons connected to the mux also dont responde when it freeze.

I cleaned up the code a bit and deleted some unused variables. Arduino is running OK now and the displays are also functional. I guess you were right about the ram issue.

As you see in my code, I have two arrays that hold the text to display on Zone 0 and 1. My aim to display static text when I switch a preset with footswitches. I would love to have a scroll effects when texts changes but couldnt manage it. To be honest my coding skills is very limited and I am heavly dependent on copy/pasting from other code samples. I am sure you already realized it as soon as you checked my full code. For about the display zone text for loops; this is the best I coould. I tried to remove P.displayAnimate() and P.displayReset() from the for loop but the displays go blank and cannot show anytext when I do that.
6  Using Arduino / LEDs and Multiplexing / 32X8 Led display multizone problem, with Parola Library (SOLVED) on: April 26, 2014, 08:55:09 am
Hi,

I am working on midi footcontroller. For display I have been using two daisy chained 8X8 matrices. Display was divided into two zones and 16X8 with two zones is working perfectly. I am using Parola Library and the daisy chained max7219 modules are from ebay.

I am need to enlarge the display to 32X8. To do this, added two more modules to the chain. My code was for two devices so it cloned the displayed text to the newly added matrices. I modified to code and set the max devices to 4 and adjusted the borders for zones. However when I change the code to work for 4 modules arduino hangs after reboot and the displays dont work. I need to mention that the scrolling text example of Parola library works fine with 4 devices. Problem exist only when I use the multizone setup.

My original code for 2 modules with 2 zones works without any problems. The related settings in this code:
Code:

//Initialize part
#define MAX_DEVICES 2

//In the setup loop
P.begin(2);
 P.setZone(0, 0, 0);
P.setZone(1, 1, 1);

To make it work with 4 modules with 2 zones, I change these settings as shown below. With these settings Arduino cannot complete the boot process.
Code:

//Initialize part
#define MAX_DEVICES 4

//In the setup loop
P.begin(2);
 P.setZone(0, 0, 2);
P.setZone(1, 3, 3);

I checked the mutlizone examples that are available in Parola library but they are causing the same problem..

Does anyone have an idea about what I am doing wrong?

I am using Arduino Micro and the full code of my project is attached.
7  Using Arduino / Programming Questions / Re: Predefined int matrix to update via serial from Processing on: April 01, 2014, 02:02:13 pm
It is more clear now. Then just need to convert the multi-dimensional matrix to one single matrix. If I get it correct the following calculation would give me the location address to read or write of the value I want.
Code:
prsBtState[x][y];
address = (x * 8) - (8 - y) - 1;
8  Using Arduino / Programming Questions / Re: Predefined int matrix to update via serial from Processing on: April 01, 2014, 12:18:08 pm
I am confused about writing and reading matrix variables from EEPROM. I have read & write single values before but never did it with matrix.

But my main confusion is about the write order. As I said I have predifened values but these values should be updateable later on. If I write these predefined values to EEPROM at the setup loop it will reset the updates at each restart. Should I compile the skecth two times? First to upload the predifed values to EEPROM with EEPROM.write() in setup and then remove the write command and change it EEPROM.read() to retrive the data stored in the EEPROM?
9  Using Arduino / Programming Questions / Re: Predefined int matrix to update via serial from Processing on: April 01, 2014, 11:20:58 am
Thanks. I got your point and updated the code to change the data type to byte.
10  Using Arduino / Programming Questions / Re: Predefined int matrix to update via serial from Processing on: April 01, 2014, 10:39:58 am
The button state values are declared as int. The a preset is loaded i read the corresponded values from the matrix and update the button state variable with it.

Is it wrong? Shall I use another data type?
11  Using Arduino / Programming Questions / Predefined int matrix to update via serial from Processing on: April 01, 2014, 10:13:13 am
Hi,

I am working on a midi controller project. The controller has a preset mode. When a preset is selected it gets the button states predefined in prsBtState variable and updates the current butoon states.

The prsBtState state variable is a 20x8 int matrix.

Code:
int prsBtState[20][8] ={
                          {1, 0, 0, 0, 0, 0, 0, 0},//A1
                          {0, 1, 0, 0, 0, 0, 0, 0},//A2
                          {0, 0, 1, 0, 0, 0, 0, 0},//A3
                          {0, 0, 0, 1, 0, 0, 0, 0},//A4
                          {0, 0, 0, 0, 1, 0, 0, 0},//B1
                          {0, 0, 0, 0, 0, 1, 0, 0},//B2
                          {0, 0, 0, 0, 0, 0, 1, 0},//B3
                          {0, 0, 0, 0, 0, 0, 0, 1},//B4
                          {0, 1, 0, 1, 0, 1, 0, 1},//C1
                          {1, 1, 1, 1, 1, 1, 1, 1},//C2
                          {0, 0, 0, 0, 0, 0, 0, 0},//C3
                          {1, 0, 1, 0, 1, 0, 1, 0},//C4
                          {1, 1, 1, 1, 1, 1, 1, 1},//D1
                          {0, 0, 0, 0, 0, 0, 0, 0},//D2
                          {1, 0, 1, 0, 1, 0, 1, 0},//D3
                          {0, 1, 0, 1, 0, 1, 0, 1},//D4
                          {0, 0, 0, 0, 0, 0, 0, 0},//E1
                          {1, 0, 1, 0, 1, 0, 1, 0},//E2
                          {0, 1, 0, 1, 0, 1, 0, 1},//E3
                          {1, 1, 1, 1, 1, 1, 1, 1}//E4
                          };

The current sketch is working perfect. However each time I want update the predefined presets I need to change the sketch and recompile it. Now I want to build a custom GUI (I am planning to use processing) to update the presets. The goal is send the preset updates via serial to arduino and update the prsBtState. I think I need to store prsBtState in the EEPROM in order to achive this.

I am correct; how can I store this int matrix in EERPOM?
I am wrong; what is the best way to achive my goal?

Thanks in advance.
12  Using Arduino / Audio / Re: Arduino Micro and MIDI Library on: February 15, 2014, 11:29:40 am
Thank you. I have completely forgot about this topic.

I have edited the midi.h file in ordet to use the midi library with midi din connected to TX pin on Arduino Micro or Leonardo.

To do that:
1 - Open; MIDI.h with a text editor
2 - Find line; #define USE_SERIAL_PORT   Serial
3 - Replace; Serial with Serial1
4 - Save&Close file

13  Using Arduino / LEDs and Multiplexing / Re: Cascade two 4051 to read 16 buttons on: February 08, 2014, 05:50:05 am
Thank you so much Mike. I followed your suggestions and it is working now.

Here is the final code two read from two cascaded 4051s, for future reference...

Code:
int b0 = 0;
int b1 = 0;
int b2 = 0;

const int mux1 = A0;
const int mux2 = A1;

int buttonValue[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int lastButtonValue[16] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
const int ledPin =  13; 

void setup(){

  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT); 
  pinMode(4, OUTPUT); 
  pinMode(ledPin, OUTPUT);
}

void loop () {

muxone();
muxtwo();
}

void muxone () {

for (int buttonCount = 0; buttonCount < 8; buttonCount++) {
    b0 = bitRead(buttonCount,0);
    b1 = bitRead(buttonCount,1);
    b2 = bitRead(buttonCount,2);

    digitalWrite(4,b0);
    digitalWrite(3,b1);
    digitalWrite(2,b2);

    buttonValue[buttonCount] = digitalRead(mux1);
 
   
    if(buttonValue[buttonCount] == LOW && lastButtonValue[buttonCount] == HIGH) {
      digitalWrite(ledPin, HIGH);
    }

    if(buttonValue[buttonCount] == HIGH && lastButtonValue[buttonCount] == LOW) {
      digitalWrite(ledPin, LOW); 
      }   
      lastButtonValue[buttonCount] = buttonValue[buttonCount];
  }
 
  }
 
 
  void muxtwo () {

for (int buttonCount = 0; buttonCount < 16; buttonCount++) {
    b0 = bitRead(buttonCount,0);
    b1 = bitRead(buttonCount,1);
    b2 = bitRead(buttonCount,2);

    digitalWrite(4,b0);
    digitalWrite(3,b1);
    digitalWrite(2,b2);
    buttonValue[buttonCount + 8] = digitalRead(mux2);
   
    if(buttonValue[buttonCount] == LOW && lastButtonValue[buttonCount] == HIGH) {
      digitalWrite(ledPin, HIGH);
    }

    if(buttonValue[buttonCount] == HIGH && lastButtonValue[buttonCount] == LOW) {
      digitalWrite(ledPin, LOW); 
      }   
      lastButtonValue[buttonCount] = buttonValue[buttonCount];
  }
 
  }
14  Using Arduino / LEDs and Multiplexing / Re: Cascade two 4051 to read 16 buttons on: February 03, 2014, 01:56:55 am
Thanks for your input Mike. I have adopted the part of the code that scans the inputs from other projects.

http://forum.arduino.cc/index.php?topic=69837.0 
http://forum.arduino.cc/index.php/topic,21547.0.html

These are my source projects. They are all using the same login with two 4051 chips

Code:
for (int buttonCount = 0; buttonCount < 8; buttonCount++) {
    b0 = bitRead(buttonCount,0);
    b1 = bitRead(buttonCount,1);
    b2 = bitRead(buttonCount,2);

    digitalWrite(4,b0);
    digitalWrite(3,b1);
    digitalWrite(2,b2);
 
    buttonValue[buttonCount] = digitalRead(mux1);
 
    buttonValue[buttonCount + 8] = digitalRead(mux2);

buttonvalue stores 16 value array variable.  When I read "digitalRead(mux1);" Button count should go from 0-7 and I should be able to parshe the pin values of the first mux into the first 8 values of the buttonValue array variable. Then, "digitalRead(mux2)" should continue and "buttonValue[buttonCount + 8]" should register the pinvalues from the second mux into 8the to 15th values of the array. The for loop is going from 0 to 7 since I have two chips, and the reads from the second chip is incremented by 8 "buttonCount + 8" inorder to be able assign values to the second half of the 16 value array variable.

I have also suspected from the same part while experimenting and have change "buttonCount < 8;" part of the for loop to "buttonCount < 16;" and tested. It did not help. the same problem continued.

I think you are right about the problematic part but I do not know how to solve it. I need to read two different chips in a single for loop and then assign the 8 input readings from the first chip to the first 8 values of an array variable and the 8 other input values from the second chip to the second half of the same array.
15  Using Arduino / LEDs and Multiplexing / Re: Cascade two 4051 to read 16 buttons on: February 02, 2014, 03:43:16 pm
sorry I forgot to mention, my data lines are also using pins 2,3,4 on my circuit,  as it is in the code. I have added the wiring picture to give a reference to cascade type I am using.  I have modified the circuit while coding. Two chips are sharing the same data pins connected to oins 2,3,4 and they have individually connected to A0 and A1 pins for read channel.

You have no supply decoupling on any chips.
You never seem to address the second mux chip in the lower part of the code with all the ifs in it.

Can you open up this a bit? I dont really know how to read from the second chip. I am searching for an reference tutorial for the last two days and this is the result with I could find.

Note: I am using Arduino micro
Pages: [1] 2