Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / multiPurpose byte - Can I get more? on: August 22, 2014, 09:19:31 pm
Can anyone suggest any bit tricks that will get me beyond 0 to 15 for a single byte that represents 2 distinct variables?  I'd like to extend beyond 16 nodeIDs.

Thanks, Dan!

Code:
// http://www.rapidtables.com/code/text/ascii-table.htm

byte nodeID = 15; // 0 to 15
byte pNum = 0;    // 0 to 15

void printByte(byte data) {
    for (byte mask = 0x80; mask; mask >>= 1) {
        Serial.print(mask&data?'1':'0');
    }
    Serial.println();
}

void setup() {
  Serial.begin(57600);
  byte testByte = (nodeID << 4) | (pNum);
  printByte(testByte);
  byte newNode = (testByte >> 4);
  byte newNum = (testByte & 0x0F);
  Serial.println(newNode);
  Serial.println(newNum);

}

void loop() {

}
.
2  Using Arduino / Sensors / Re: Phototransistor - Pulse Width Tips: Position and Angle on: August 04, 2014, 10:02:34 pm
No motor involved.

I'm referring to the phototransistor as the sensor and it's distance and angle from that fixed pulse source, an IR led.
I had the sensor right up against the IR led which reduced the resolution.  Pulling it back from the IR source was the key.

3  Using Arduino / Sensors / Re: Problem with an array of soil moisture sensors on: August 04, 2014, 09:34:16 pm
All those comparator lm393 sensors "out there" give a digital output (most active-low).  The analog output is really just a voltage divider and bypasses the chip all together.  Are you using the comparator output as digital, adjustable by the potentiometer, or the A0 pin?

Without getting into smoothing, averages, and blink without delay.  analogRead can be noisy.  Just add a delay(50);  between each reading.  You'll see a difference.  If the sensors work one-by-one you're reading them too fast and picking up noise from the other.

-Dan

4  Using Arduino / Sensors / Phototransistor - Pulse Width Tips: Position and Angle on: August 04, 2014, 08:17:26 pm
I'd just like to share my experience with pulse counting.  I'm currently doing an electric meter pulse counting project and it works great.   However when the pulse rate increased, the accuracy decreased.  I was wondering why I was getting maxed out on my counts (ms per count).  I thought I had a problem with the sensor (capacitance issue I thought), it turns out the sensor is plenty fast.  The datasheet say it has a 5us recovery.  When you have no control over the pulse width of what's being measured, this helped out a lot.

You can vary the distance and angle from the pulse to get better resolution.

I hope this helps others.

Cheers, Dan

Code:
const byte ledPin = 13;  // LED pin
const byte inputPin = 2; // Photo transistor input, common emitter config 10K resistor
int sensorState = HIGH;  // we start HIGH, detecting LOW Trigger
byte val = 0; // variable for reading the pin status

unsigned long startPulse;
unsigned long timeNow;

void setup() {
  Serial.begin(57600);
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare sensor as input
  digitalWrite(inputPin, HIGH); // enable pull-up, we are detecting LOW
}

void loop() {
  val = digitalRead(inputPin); // read input value
  if (val == LOW) { // check if the input is LOW
    PORTB |= _BV(PORTB5);  // D13 HIGH, faster than digitalWrite(ledPin, HIGH);
    if (sensorState == HIGH) {
      startPulse = millis();
      sensorState = LOW;
    }
  }
  else {
    PORTB &= ~_BV(PORTB5); // D13 LOW, faster than digitalWrite(ledPin, LOW);
    if (sensorState == LOW){
      timeNow = millis();
      Serial.println(timeNow-startPulse);
      sensorState = HIGH;
    }
  }
}
5  Using Arduino / Motors, Mechanics, and Power / Re: Pin out resistor on: June 18, 2014, 09:22:21 pm
Always use a 1K in the base, with 5V this gives you a base current of 5mA.  You can go lower on the base resistor, but don't exceed 20ma.

Use an external power supply, without knowing all the details, it appears you're connected power is USB only and the port is limiting current to your circuit.

...I hope this helps!!!
6  Using Arduino / LEDs and Multiplexing / Re: Simple Bicolor LED too dim - Arduino Uno on: June 18, 2014, 08:59:02 pm
Pins default to INPUT, therefore high-impedance, which would make the LED dimmer if they're not declared as an OUTPUT.

http://arduino.cc/en/Tutorial/DigitalPins
7  General Category / General Discussion / Littlebits, a lesson in magnetism or electronics? on: June 18, 2014, 08:50:16 pm
I was just introduced to littlebits via an email on the Arduino forum.  I just don't get it?  for anyone 8+ years of age; I'd rather get 50 cents worth of leds and teach polarity, resistance, regulation and such ( over-current and burn out a few in the teaching process).  ...not magnets.  I think these "bits" dumb down the electronics aspect of what's being built.  ...maybe it will fuel its users beyond the magnets and hopefully they'll understand what's really happening and they realize the magnets are only a conductor.

If you gave a littlebit user a 1K resistor, an LED, and a 9v battery, would they ask "where are the magnets"?

...just my thoughts on the "bits"
8  Using Arduino / Networking, Protocols, and Devices / Re: new library UIPEthernet: uIP adapted to Arduino for ENC28J60 on: June 18, 2014, 06:03:03 pm
@ntruchsess

I stopped by the forum to say thanks for the lib. I got my first ENC28J60 last week; I haven't had any problems so far and I've tried many programs to start...now I'm coding my own and learning as very little jquery as I need to :-)

There really hasn't been anything I've come across that doesn't work.  The tip to to disable UDP and tweak the number of connections in /utility/uipethernet-conf.h has resolved any issues I've had.

..thanks again! -Dan
9  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.
10  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.

11  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!
12  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.

13  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.
}
14  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/
15  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.



Pages: [1] 2