Show Posts
Pages: [1]
1  Using Arduino / General Electronics / Re: Trying to make a mic preamp on: October 04, 2013, 07:04:37 pm
Measure the resistance of the mic leads between the white (audio out) and red wire (pos).  Put the multimeter in 20k range.  What's the value?  The mic might be internally, what is called "biased" already.  If this is the case, the 5v resistor may not be needed.

This is a great resource for mics.

http://www.epanorama.net/circuits/microphone_powering.html

...don't give up on this project, you'll get it going!  Plenty of ppl to help.
2  Using Arduino / General Electronics / Re: Trying to make a mic preamp on: October 02, 2013, 06:41:32 pm
Yes, the LM386 will work fine, start off with that.

The LM386 has one amp, most with 8 pins have 2 amps.  Take a look here, you'll see that pins are different between single and dual.
http://www.allaboutcircuits.com/vol_3/chpt_8/3.html

Without getting too much into opamps, most circuits that require them, you can use any package you like, just note the pin differences for this mic preamp example.

"These give half of VCC at zero SPL:"  Arduino at 5 volts, no sound will be 2.5v (or AnalogRead ~511).

The 3-wire mic shouldn't be any different.  VCC, GND, AUD out through 10uf Cap.
http://lowvoltage.wordpress.com/2011/05/15/lm386-mic-amp/

Stick with the DIY, you'll learn more.  Don't buy one of those premade sensors, they only give you an ON/OFF via a comparator based on a threshold you set.

3  Using Arduino / General Electronics / Re: Trying to make a mic preamp on: October 02, 2013, 05:22:32 pm
I've had really good results with these single stage preamps, the quality of the opamp/mic make a difference.  Use a socket for opamp so you can try different ones that are pin compatible.

I usually use dual opamp, as there are many more of these.  Careful though, pins are different on single and dual opamps.

These give half of VCC at zero SPL:
http://lowvoltage.wordpress.com/2011/05/21/lm358-mic-amp/
http://lowvoltage.wordpress.com/2011/05/15/lm386-mic-amp/

Cheers!
4  Using Arduino / Storage / Re: LC Studio Card Reader - BAD PCB on: October 02, 2013, 04:41:49 pm
I have an LC Studio labeled reader that works fine with 5v and 3.3v.  The first post mentioned "noise" and that the caps for the regulator were not grounded.  C3(input and other side to ground) C4(output and other side to ground).  My LC Studio has proper connections, proper grounds and I don't have issues.

Check the LM1117 regulator datasheet pinouts: mine is (1 Gnd, 2-Vout, 3-Vin).  You might have shorted the supply to ground as the schematic pins are not left to right with the datasheet.  Always check datasheet, and test with dmm if you can.

If you're using sdfat check the "troubleshooting.txt" in the lib directory.  Your card could be an issue as well.  Try others if you have them.  Sometimes it's hit or miss with the cards.  I haven't used anything >4gb.
Also, I find you must use SPI_HALF_SPEED with these adapters.

Posting code might help too.

5  Using Arduino / Storage / Re: This example doesn't work on: September 26, 2013, 10:22:15 am
I had similar issues with some of my older programs when I upgraded the library to "sdfatlib20130629".

Those functions have changed in the new library.  The new functions return boolean.  Check the new docs located in library directory under "html".

this link might help too.
http://www.ladyada.net/learn/arduino/ethfiles.html

Maybe this will help.  **Warning** Compiles, but untested.

Code:
/*
    Basic example reading and writing to the microSD shield
 Based on the SdFat Library by Bill Greiman
 SparkFun Electronics
 
 This example creates a file (or opens it if the file already exists) named 'Test.txt.'
 A string with the value 'Millis: (number of millis)' is appended to the end of the file.
 After writing to the file, the contents of the entire file are printed to the serial port.
 */

//Add the SdFat Libraries
#include <SdFat.h>
#include <SdFatUtil.h>
#include <ctype.h>

//Create the variables to be used by SdFat Library
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;

#define SD_CHIP_SELECT  10 // Your select pin (4 on ethernet shield)

char name[] = "Test.txt";     //Create an array that contains the name of our file.
char contents[256];           //This will be a data buffer for writing contents to the file.
char in_char=0;
int index=0;                  //Index will keep track of our position within the contents buffer.

void setup(void)
{
  Serial.begin(9600);        //Start a serial connection.
 
  // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  if (!card.init(SPI_HALF_SPEED, SD_CHIP_SELECT)) Serial.println("card.init failed!");
 
  // initialize a FAT volume
  if (!volume.init(&card)) Serial.println("vol.init failed!");
 
  //Initialize a volume on the SD card.
  if (!root.openRoot(&volume)) Serial.println("openRoot failed");
 
  //volume.init(card);         //Initialize a volume on the SD card.
  //root.openRoot(volume);     //Open the root directory in the volume.
}
void loop(void){   
  file.open(&root, name, O_CREAT | O_APPEND | O_WRITE);    //Open or create the file 'name' in 'root' for writing to the end of the file.
  sprintf(contents, "Millis: %d    ", millis());    //Copy the letters 'Millis: ' followed by the integer value of the millis() function into the 'contents' array.
  file.print(contents);    //Write the 'contents' array to the end of the file.
  file.close();            //Close the file.

  file.open(&root, name, O_READ);    //Open the file in read mode.
  in_char=file.read();              //Get the first byte in the file.
  //Keep reading characters from the file until we get an error or reach the end of the file. (This will output the entire contents of the file).
  while(in_char >=0){            //If the value of the character is less than 0 we've reached the end of the file.
    Serial.print(in_char);    //Print the current character
    in_char=file.read();      //Get the next character
  }
  file.close();    //Close the file
  delay(1000);     //Wait 1 second before repeating the process.
}
6  Using Arduino / Programming Questions / Re: Shifting 2D Array - 8x8 RGB on: August 15, 2013, 08:10:50 pm
I've invited the author of the nice lib to join the discussion.  Without this lib, the demo code provided by iteadstudio leaves nothing to be desired.

http://blog.lincomatic.com/?p=148

Kudos to lincomatic and his instructables post:
http://www.instructables.com/id/Lampduino-an-8x8-RGB-Floor-Lamp/step16/Programming-the-Colorduino/
7  Using Arduino / Programming Questions / Re: Shifting 2D Array - 8x8 RGB on: August 15, 2013, 07:36:04 pm
I experimented with the memcpy function and it seems to work very well.

Code:
byte display_byte[3][64];   // display array - 64 bytes x 3 colours
byte buffer_byte[3][64];    // buffer copy test

void mem() {
  memcpy(buffer_byte, display_byte, sizeof(buffer_byte));  // Copies Buffer display_byte to buffer_byte
}

I tried changing the 2D array to 3D, no luck.  Trying to shift every 8th byte in one direction or another would be a nightmare. In looking at the i2c slave code, the slave sets x,y coordinates based on incoming data (64 bytes for each color). i.e.

Code:
   if (c == 0){
      for (byte x = 0; x < 8; x++){
        for (byte y = 0; y < 8; y++){
           PixelRGB *p = Colorduino.GetPixel(x,y);  // my comment: Get.Pixel, actually "sets pixel" for writing in the offscreen framebuffer
           p->r = Wire.read();
        }
      }
    }




Code:
{
  
  //1 pixel = 3 bytes B00000000 B00000000 B00000000.
  //We send R then G then B bytes as 3 separate transfers
  //This is because if we make the I2C buffer too large, we run out of SRAM for other things on our master Arduino
  
  if (Wire.available()>66) { //when buffer full, process data. 66 =  start byte + colour + 64 pixel data + end byte
    
    // error check - make sure our data starts with the right byte  
    if (Wire.read() != START_OF_DATA) {
      //else handle error by reading remaining data until end of data marker (if available)
      while (Wire.available()>0 && Wire.read()!=END_OF_DATA) {}      
      return;
    }

    byte c = Wire.read(); //read our color byte so we know if these are the R, G or B pixels.
    
    //depeding on c read pixels in as R G or B
    //read red display data
    if (c == 0){
      for (byte x = 0; x < 8; x++){
        for (byte y = 0; y < 8; y++){
           PixelRGB *p = Colorduino.GetPixel(x,y);
           p->r = Wire.read();
        }
      }
    }
    
    //read green display data
    if (c == 1){
      for (byte x = 0; x < 8; x++){
        for (byte y = 0; y < 8; y++){
          PixelRGB *p = Colorduino.GetPixel(x,y);
           p->g = Wire.read();
        }
      }
    }
    
    //read blue display data
    if (c == 2){
      for (byte x = 0; x < 8; x++){
        for (byte y = 0; y < 8; y++){
           PixelRGB *p = Colorduino.GetPixel(x,y);
           p->b = Wire.read();
        }
      }
    }
    
    //read end of data marker
    if (Wire.read()==END_OF_DATA) {
      //if colour is blue, then update display
      if (c == 2){Colorduino.FlipPage();}
    }
  }
}

I'm thinking I could have the slave do the work in shifting pixels by adding additional i2c commands:

the following functions exist in the lib:

Code:
 void FlipPage() {  // my comment: offscreen to active framebuffer
    cli();
    // swap frame buffers
    PixelRGB *tmp = curDrawFrame;
    curDrawFrame = curWriteFrame;
    curWriteFrame = tmp;
    sei();
  }

  // get a pixel for writing in the offscreen framebuffer
  PixelRGB *GetPixel(unsigned char x,unsigned char y) {
    return curWriteFrame + (y * ColorduinoScreenWidth) + x;
  }

  // get a pixel from the active framebuffer
  PixelRGB *GetDrawPixel(unsigned char x,unsigned char y) {
    return curDrawFrame + (y * ColorduinoScreenWidth) + x;
  }

  // set a pixel in the offscreen frame buffer
  void SetPixel(unsigned char x, unsigned char y, unsigned char r, unsigned char g, unsigned char b)
  {
    PixelRGB *p = GetPixel(x,y);
    p->r = r;
    p->g = g;
    p->b = b;
  }


Thanks again for your time.



8  Using Arduino / Programming Questions / Re: Help with Serial.print on: August 14, 2013, 09:56:16 pm
What does "nothing prints" mean?

...are you getting ?

level
min
max

    Serial.print("level "),
    Serial.println(channelValue),
    Serial.print("  min  "),
    Serial.print(channelMinValue),
    Serial.print{"  max  "),
    Serial.println(channelMaxValue);

...if the values don't get populated, make them global.  I have no problem declaring a variable inside a function and then Serial.print"ing" it within that function.

I dunno.
9  Using Arduino / Programming Questions / Re: Shifting 2D Array - 8x8 RGB on: August 14, 2013, 09:05:52 pm
Thanks for the reply.

Pixels shifted should be completely discarded (turned black)...like scrolling text or animations that leave view.

I do have enough room to copy the buffer.  I checked it with:

int freeRam () {
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

...I have 1157 free (328 chip)

I'm hoping just to manipulate the current buffer, but adding another could be of other use too.

I just want to fill the shifted buffer (or copy) with black:

byte display_byte[0][pixelnum]  // red   (0,pixelnum)
byte display_byte[1][pixelnum]  // grn   (0,pixelnum)
byte display_byte[2][pixelnum]  // blu   (0,pixelnum)

Breaking the 64 pixels into rows and columns does help.

In the library, this function: ...converts the x,y coordinates to pixels nums.

Code:
//update display buffer using x,y,r,g,b format
void display(byte x, byte y, byte r, byte g, byte b) {
  byte p = (y*8)+x;   //convert from x,y to pixel number in array
  display_byte[0][p] = r;
  display_byte[1][p] = g;
  display_byte[2][p] = b;
}

Thanks

10  Using Arduino / Programming Questions / Shifting 2D Array - 8x8 RGB on: August 14, 2013, 06:17:04 pm
Greetings forum,

I hope someone could help me out in shifting a 2D array.  I recently bought a Colorduino and I have coded many cool patterns and animations.  However, I found the need to shift the buffer to create better animations and make the code more streamlined.

I'd like to shiftup, shiftdown, shiftleft, and shiftright.  The Colorduino is an 8x8 RGB matrix.

The display buffer looks like this:

byte display_byte[3][64];   //display array - 64 bytes x 3 colours.  0 red, 1 grn, 2 blu    64 pixels

I'd like to shift the display and then call directly:

Code:
//send display buffer to display via i2c
void update_display(byte addr) {   
  BlinkM_sendBuffer(addr, 0, display_byte[0]);   
  BlinkM_sendBuffer(addr, 1, display_byte[1]);   
  BlinkM_sendBuffer(addr, 2, display_byte[2]); 
}

I'd like to create functions like this, where n is num of shifts:
void shiftRight(int n) {

}

I've tried some code here, but nothing meaningful to post:
http://www.learningace.com/doc/4992024/3105e0e2881142fd218f9b6f05c079cb/r-multiarrays
http://www.cplusplus.com/forum/beginner/1521/

99% of the time I've found answers to all my C++ and Arduino questions on the net.

Thanks for your time.








11  Topics / Home Automation and Networked Objects / X10 - CM11a Receive/Monitor Powerline Commands on: April 26, 2013, 11:25:33 am
Greetings!

I thought I'd share a Proof of Concept for receiving powerline commands from an X10 CM11a serial interface.  What it does is recieve commands via CM11a <> TTL shifter <> software serial and print commands to Arduino hardware serial.

This could be modified to control or display commands with your arduino.  The CM11a is an RS232 device and there's no need for the "zero-crossing" based PSC05/TW523 module.

You MUST use a ttl level shifter, do NOT connect an RS232 device directly to your arduino.

I hope someone likes this, I could not find any other code to receive commands with CM11a.  I'm a hobbyist; the code is what it is.  I hope this might inspire someone to make it better.

Thanks,  Dan G.

Credits:
- Arduino folks, of course!
- "LJRob" for the initial sketch for sending commands via CM11a
  see: http://arduino.cc/forum/index.php?topic=136227.0
- BroHogan - Parse code at http://playground.arduino.cc/X10/ReceiveX10

Arduino IDE 1.0.3

----

Code:
/*
Proof of Concept: CM11a Powerline Command Monitor
Author: Dan G.

Recieve commands via CM11a <> TTL shifter <>
software serial and print commands to Arduino hardware serial.

Since the PSC05/TW523 modules are no longer made.  CM11a can be used to receive PLC.
They are much cheaper and available.

Do NOT connect CM11a directly to Arduino, you MUST use TTL level shifter.

Search for "cm11a_protocol.txt" for more details.

Credits:
- Arduino folks, of course!
- "LJRob" for the initial sketch for sending commands via CM11a
  see: http://arduino.cc/forum/index.php?topic=136227.0
- BroHogan - Parse code at http://playground.arduino.cc/X10/ReceiveX10
*/

#define ON   B10000000  // Bitshifted ON
#define OFF  B11000000  // Bitshifted OFF

byte lookup[16] = {  // Lookup table for House and Unit Code
  //Binary  House Unit
  B0110,  // A 1
  B1110,  // B 2
  B0010,  // C 3
  B1010,  // D 4
  B0001,  // E 5
  B1001,  // F 6
  B0101,  // G 7
  B1101,  // H 8
  B0111,  // I 9
  B1111,  // J 10
  B0011,  // K 11
  B1011,  // L 12
  B0000,  // M 13
  B1000,  // N 14
  B0100,  // O 15
  B1100,  // P 16
};

#include <SoftwareSerial.h> // For the TTL to RS232
SoftwareSerial X10Serial(2, 3); // RX, TX to TTL RS232



byte incomingByte; // Controller status
byte Hc;           // Housecode
char chrHc = Hc;   // Housecode to char
byte U;            // Unit
byte Cmd;          // ON or OFF

//Serial buffer
byte serIn; // var that will hold the bytes-in read from the serialBuffer
byte serInString[9]; // CM11a can send up to 10 bytes (program only handles 3 bytes)
int serInIndx = 0; // index of serInString[] in which to insert the next incoming byte
int serOutIndx = 0; // index of the outgoing serInString[] array;

void setup() {

  Serial.begin(57600);
  X10Serial.begin(4800);    // X10 Baud 4800 8,NONE,1
  Serial.println("x10 CM11a Ready:");
}

void loop(){
 
  CheckX10controller();  // Check CM11a for data or power failure.
  parseX10SerialString();
 
}

// Read from X10 controller
void CheckX10controller() {

  if (X10Serial.available() > 0) {
    incomingByte = X10Serial.read();

    switch (incomingByte) {
     
      case ((byte)0xA5): // Polling: This happens the first time you plug the X10 controller in the socket or after a power cut
      delay(100);  // CM11a is slow; don't write too fast, won't work!
      X10Serial.write((byte)0x9B); // Acknowledge / Clear, This must be cleared or it will not except any other x10 commands
      delay(60);
      Serial.println("Power Supply Restored");
      break;

      case ((byte)0x5A): // Polling: When powerline command received, CM11a send this byte.
      delay(100); // CM11a is slow; don't write too fast, won't work!
      X10Serial.write((byte)0xC3);   // Send byte, initiate the data transfer.
      delay(60);
      ReadData();   
      break;
      //default:  //Used for testing only
      //ReadData(); //Used for testing only
    }
  }
}

void ReadData() {

  int sb;
  if(X10Serial.available()) {
    while (X10Serial.available()){
      sb = X10Serial.read();
      serInString[serInIndx] = sb;
      serInIndx++;
    }
  }
}

void parseX10SerialString(){
  if( serInIndx > 0) {
    //debug Serial.print("Bytes Received: ");
    //debug Serial.println(serInString[0]);
    if (serInString[1] == 0) {
      //debug Serial.print("X10 Address 2nd byte is: ");
      //debug Serial.println(serInString[1], HEX);
      //debug Serial.print("HcU in BIN: ");
      //debug Serial.println(serInString[2], BIN);
      Hc = serInString[2] >> 4;  // Gets Housecode binary
      //debug Serial.print("Hc in BIN: ");
      //debug Serial.println(Hc, BIN);
      for (byte i=0; i<16; i++){ // use lookup table for Housecode
        if (lookup[i] == Hc){
          Hc = i+65;   // this gives int House 'A' - 'P'
          char chrHc = Hc;  // Convert int Hc to Char for Serial print
          Serial.print("Housecode: ");
          Serial.println(chrHc);
          break;            // stop search when found!
        }
      }
      U = serInString[2] << 4;   // Bitshift for Unit
      U = U >> 4; // Final "bitdance" for Unit
      //debug Serial.print("U in BIN: ");
      //debug Serial.println(U, BIN);
      for (byte i=0; i<16; i++){  // use lookup table for Unit
        if (lookup[i] == U){
          U = i+1;        // this gives Unit 1-16
          Serial.print("Unit: ");
          Serial.println(U);
          break;          // stop search when found!
        }
      }
    }
    if (serInString[1] == 1) {
      //debug Serial.print("X10 Function 2nd byte is: ");
      //debug Serial.println(serInString[1], BIN);
      //debug Serial.print("Function: ");
      Cmd = serInString[2] << 6; // Bitshift out redundant Housecode
      Serial.print("Command: ");
      if(Cmd == B10000000)Serial.println("ON ");
      if(Cmd == B11000000)Serial.println("OFF ");
      //debug Serial.print("binary: ");
      //debug Serial.println(Cmd, BIN);
    }
  }
  //reset all the functions to be able to fill the string back with content
  serOutIndx = 0;
  serInIndx = 0;
}





12  Using Arduino / Programming Questions / Re: Trying to use the Tone library, but getting compile errors on: March 23, 2013, 08:00:27 pm
It's much easier (for me) to diff changes to libraries.

It is what it is!!!  It does resolve the issue which is what the thread is about.


13  Using Arduino / Programming Questions / Re: Trying to use the Tone library, but getting compile errors on: March 21, 2013, 01:40:11 pm
I too had this issue.  I'm using IDE 1.0.3.

Using  most recent version Arduino-Library-Tone.zip  (md5: BFA2C0FE4830AFBB999417B241807A52)
Arduino-Library-Tone.zip    Arduino Tone Library - V0006   Featured

Open "Tone.cpp" in libraries folder and change:
//**Comment this OUT begin***
// #include <avr/interrupt.h>
// #include <avr/pgmspace.h>
// #include <wiring.h>
// #include <pins_arduino.h>
// #include "Tone.h"
//**Comment this OUT end***

// Add this to Tone.cpp begin
    #include <avr/interrupt.h>
    #include <avr/pgmspace.h>
    //For Arduino 1.0
    #if ARDUINO >= 100
        #include <Arduino.h>
    #else
        #include <WProgram.h>
    #endif
    #include <pins_arduino.h>
    #include "Tone.h"
// Add this to Tone.cpp end

Hope this helps.   Thanks!
14  Using Arduino / Programming Questions / tinygps - newsoftserial and running test_with_gps_device on: November 12, 2012, 10:04:41 pm
I did a similar hack for a bluetooth GPS (B-Speech GPS20c) ttl wired directly to arduino mentioned here:
http://arduino.cc/forum/index.php?topic=106798.0

In running, tinygps v.12 and using sample program "test_with_gps_device".  Changing SoftwareSerial.h to _SS_MAX_RX_BUFF = 128 was not enough.  With this device and for use with this example program I had to go "256".  That's alot for the example and softserial.  I think the example should be trimmed down; who cares about the Coarse to London thing.

6    150  99.99951 -999.19108 505  11/13/2012 03:03:33   508  17.20   1.76   0.08  N     7087     43.14  NE    75572 5839      685

Now that I know everything works I'm off to write a program that won't require such a large use of RAM.  I hope this helps someone who didn't get all their data populated by using the example sketch.

Cheers!
15  Using Arduino / Networking, Protocols, and Devices / Re: RF24 Library: Driver for nRF24L01(+) 2.4GHz Wireless Transceiver on: October 29, 2012, 02:09:55 pm
First let me say thanks to maniacbug for the GREAT library!

I've playing around with these modules for a few weeks and decided to base my sensor xmitters on the pingpair_sleepy example.  I wanted to reduce power consumption as much as possible.

I came across a problem in the pingpair_sleepy example provided with RF24.  The ping out would only work once.

    // Power down the radio.  Note that the radio will get powered back up
    // on the next write() call.
    radio.powerDown();

When the radio was powered down, it would never come back.  Commenting out radio.powerDown(); OR adding radio.powerUp() before the radio.write call in the example works.

Maybe there's a bug that assumes a write will always powerup first.

I hope this helps someone!

My sensor works well now and draws ~20ma idle (4secs) and ~35ma (1sec) when sending data.

Thanks.

Pages: [1]