Show Posts
Pages: [1] 2 3 ... 45
1  Using Arduino / General Electronics / Re: Ua 741 OpAmp how to connect it to get a gain of 2? on: April 16, 2014, 10:10:45 am


this part works fine.
Now instead of just a voltage follower at the end I'm trying to increase the voltage 2 times.

I'm amazed that so many posts have been made and yet nobody has helped you yet.

Use the circuit you have, but instead of connecting the op-amp output directly to the inverting input, connect it as follows:

* 10K resistor from output to inverting input.
* 10K resistor from inverting input to ground.

That will set your op amp to have a gain of 2 (it currently has a gain of 1).

Also, your circuit will only produce about +7 or so volts max with a +/-9 volt supply (the output obviously cannot go higher than the supply voltage). If you need more than +7, then increase the supply voltage to +/-12 or +/-15 volts.

Usually, the supply voltages do not have to be equal. If you only need a positive output, a +5, -15 volt supply would be OK.

Lastly, although the 741 op-amp is an older design, there's nothing wrong with it and there's no reason to use something different.

Good luck.
2  Using Arduino / General Electronics / Re: Instead of IR transmitter / receiver, wire directly? on: April 16, 2014, 09:58:26 am
Hy

I currently use an Arduino to control a device over an IR LED.
Is it possible to use two wires directly from the Arduino
output to the IR of the device and use the same code I used
before to control it via the IR LED?

Andy

Probably the easiest way to do it (and avoid any ground loop or polarity problems) would be to use an opto-isolator.

The circuit that drives the IR LED would go to the opto input and it's output would go to the IR receiver circuit.
3  Using Arduino / Programming Questions / Re: Need help - Array with different size elements on: April 07, 2014, 12:39:17 pm
How is the renderer (the program that draws the characters) supposed to know how many bytes are in each character representation?

Good question. You can't see it because I hacked out pieces of the table to constrain the size for the example, but each data set ends with 0xFF, 0xFF, 0x00 (which means to the renderer, X=-1, Y=-1, Pen=Up).
4  Using Arduino / Project Guidance / Re: create audio file from arduino sensor data on: April 07, 2014, 08:36:20 am
Hello,
Does anyone know an approach to create an audio file from the signal my arduino is reading off of the analog pin? I am currently reading the sensor and sampling it and sending the digital signal to the computer over the serial port. is there any way to use processing to create an audio file from the data from the serial port?

You can use a serial terminal and "download" the data to a file. Have your Arduino send the data as ascii hex values, download the data as text, then externally convert the text file to a binary file and add a WAV header to it.

Attached is a utility I wrote a long time ago called "wavefix". It can edit existing or create new WAV headers for files. I wrote it specifically for converting data files into sound files (actually, to listen to the sound of a combustion chamber pressure transducer in a small rocket engine by adding a WAV header to the transducer data).

The attached ZIP file has a Win32 console EXE file precompiled and the C source code. It will compile in Linux and will probably compile in MacOS (haven't tried it on a Mac).

Hope this helps.
5  Using Arduino / Programming Questions / Re: Need help - Array with different size elements on: April 07, 2014, 07:24:59 am
A series of Iliffe vectors, pointing into a second linear array.

Sorry, I have no clue what you mean.
6  Using Arduino / Programming Questions / Re: Why == works in an if statement? on: April 07, 2014, 07:22:52 am
This is a pretty basic question.   I believe that I have seen online examples of if statements with just a simple < or > operator, but never with just a simple = operator.  Is the == operator always needed within an an expression found in the if statement? Hoping someone with more experience would be willing to share the reason.

"==" means "does it equal?"

"=" means "set this to that".

Example:
    X = 3;
    if (X == 4) {
        print ("It's not the same!"); <-- this gets printed because 3 is not equal to 4
    } else {
        print ("It matches!");
    }


Now watch what happens here:
    X = 3;
    if (X = 4) { <-- this SETS X to a value of 4
        print ("It's not the same!");
    } else {
        print ("It matches!"); <-- this gets printed because setting X to anything returns boolean "true"
    }


Make sense?
7  Using Arduino / Programming Questions / Need help - Array with different size elements on: April 07, 2014, 07:14:53 am
Hi all,

I am trying to figure out how to create an array that has elements of different lengths. Each element will contain X/Y coordinates to draw vector characters, and I need to point to any element at random... like this:

Code:
static const uint8_t c30[] PROGMEM = { // char 0x30 (0)
    0x14,0x00,0x00,
    0x09,0x1c,0x01,
    0x04,0x18,0x01,
};

static const uint8_t c31[] PROGMEM = { // char 0x31 (1)
    0x14,0x00,0x00,
    0x06,0x18,0x01,
    0x08,0x19,0x01,
    0x0b,0x1c,0x01,
    0x0b,0x07,0x01,
};

static const uint8_t c32[] PROGMEM = { // char 0x32 (2)
    0x14,0x00,0x00,
    0x04,0x17,0x01,
    0x04,0x18,0x01,
    0x05,0x1a,0x01,
    0x06,0x1b,0x01,
    0x08,0x1c,0x01,
    0x03,0x07,0x01,
    0x11,0x07,0x01,
};
//............. etc............

static const uint16_t pointers[] PROGMEM = {
    c30, c31, c32, etc........
};

Note that each set of coordinates (c30, c31, c32, etc...) contain a different number of bytes. The last lines in the code example (pointers) is what I'm trying to do... for example if I do a pgm_read_word (pointers + 0) I want it to point to the first byte in c30, pointers + 1 would point to the first byte in c31, etc... (that is, I want the address of each character set).

I hope I described this correctly. Any ideas how to do this will be appreciated. Thanks!

-- Roger
8  Using Arduino / Programming Questions / Re: Arduino UNO R3 16u2 Firmware Restore on: April 06, 2014, 03:09:51 pm
Thanks Krupski for the quick and detailed reply. Although I would classify myself as an experienced C programmer,  I haven't quite figured out everything with the Arduino or AVR tools yet. I'll have to go find an AVR tool to use for the programmer - I use a Win7 platform. I was hoping there was a function built into the Arduino IDE that I was missing but guess not. Thanks again.

The command line I posted was generated by my script. That command line (an AVRDUDE command) will work equally well in Windows. The script, however, will not.

All you have to do is click Start, then Run, then type "cmd". A black screen with white letters will open. That's a command line interface.

Then just copy and paste the command I posted into the window and press enter.

Of course as I said, edit the command line accordingly to match your hardware (for example, your COM port will be something like "COM3" rather than "usb").

That command line should run AVRDUDE, read the 16u2 chip and record all the stuff in the filenames I mentioned previously.

If you get a "Command or path not found" error message, that's because AVRDUDE.EXE isn't in your path. You'll have to find where it is and then type in the whole path.

For example, instead of just "avrdude" you may need something like "C:\Program Files\Arduino_105\hardware\tools\avrdude.exe" (wherever your AVRDUDE is - you'll have to find it).

When you're done, type "exit" and hit enter to close the command window.

Hope this helps.
9  Using Arduino / Programming Questions / Re: Arduino UNO R3 16u2 Firmware Restore on: April 06, 2014, 01:00:23 pm
I have been contemplating reprogramming the UNO 16U2 in order to reconfigure the board as a joystick (according to posts elsewhere in the Forum). I would like to make sure I can restore the 16U2 to its previous state to reuse the board or in case something goes wrong. How can I locate and save the existing 16U2 firmware before I reprogram it?

Just download the original code from the chip:

Code:
avrdude -c avrispmkii -p m16u2 -P usb -b 115200 -v -U  flash:r:firmware.hex:i -U eeprom:r:firmware.eep:i -U  hfuse:r:firmware.hfu:i -U  lfuse:r:firmware.lfu:i -U  efuse:r:firmware.efu:i -U   lock:r:firmware.lck:i

Note: You may need to change the -c option (type of programmer), the -P option (the programmer port) and the -b option (programmer baud rate).

The command will produce files named "firmware.xxx" where "xxx" is "hex" (the main code), "eep" (eeprom contents), "hfu, lfu and efu" (fuse settings) and "lck" (lock settings).

If necessary, just burn these same files back into the chip and it should be restored to the exact state it started with.

Good luck.

(edit to add): Here's a Linux script that I use to read AVR chips. If you don't use Linux, you may be able to convert it to a Windows batch file - I don't know - but here it is:

Code:
#!/bin/bash

## case insensitive
shopt -s nocasematch

## $0 is the filename of the script (same as argv[0] in C)
if [[ ! $2 ]]; then {
echo
echo "usage: ${0##*/} filename chipname"
echo
exit 1
} fi

CHIP="$2" ## second command line parameter

PGMR="avrispmkii" ## programmer type
PORT="usb" ## programmer port
BAUD=115200 ## programmer baud rate
VERBOSE=1 ## higher=more info
BITCLOCK=3 ## make this larger or remove it if you get avrdude errors

FNAME=$1 ## first command line parameter
FNAME=${FNAME%%.*} # isolate filename w/o extension

ANS="N"
CMD="avrdude"

test -e $FNAME.hex

if [[ ${?} -eq 0 ]]; then {
echo
echo -n "$FNAME.hex already exists - overwrite? (yes/N) "
read ANS
} else {
ANS="yes"
} fi

if [[ "$ANS" == "y" ]]; then {
echo
echo "Type the full word \"yes\" to overwrite $FNAME.hex"
echo
exit 0
} fi

if [[ "$ANS" == "yes" ]]; then {

##  uncomment this for a bit more info
## echo
## echo "${0##*/} set for $PGMR programmer and $CHIP on port $PORT"
## echo

test -e $FNAME.hex && rm $FNAME.hex
test -e $FNAME.eep && rm $FNAME.eep
test -e $FNAME.hfu && rm $FNAME.hfu
test -e $FNAME.lfu && rm $FNAME.lfu
test -e $FNAME.efu && rm $FNAME.efu
test -e $FNAME.lck && rm $FNAME.lck

CMD+=" -c $PGMR"
CMD+=" -p $CHIP"
CMD+=" -P $PORT$NUM"
CMD+=" -b $BAUD"

## avrdude verbose mode?
if [[ $VERBOSE -gt 0 ]]; then {
CMD+=" -"
while [[ $VERBOSE -gt 0 ]]
do
CMD+="v"
VERBOSE=$[ VERBOSE-1 ]
done
} else {
CMD+=" -qqq"
} fi

## bitclock defined?
if [[ $BITCLOCK ]]; then {
CMD+=" -B $BITCLOCK"
} fi

CMD+=" -U  flash:r:$FNAME.hex:i"
CMD+=" -U eeprom:r:$FNAME.eep:i"
CMD+=" -U  hfuse:r:$FNAME.hfu:i"
CMD+=" -U  lfuse:r:$FNAME.lfu:i"
CMD+=" -U  efuse:r:$FNAME.efu:i"
CMD+=" -U   lock:r:$FNAME.lck:i"

## echo "$CMD"
$CMD

if [[ ${?} -eq 0 ]]; then {
echo
echo "+-----------------+"
echo "| === SUCCESS === |"
echo "+-----------------+"
echo
beep -f 880 -l 100;
beep -f 770 -l 100;
beep -f 660 -l 100;
beep -f 550 -l 100;
beep -f 440 -l 100;
beep -f 330 -l 100;
beep -f 220 -l 100;
exit 0
} else {
echo
echo "+-----------------+"
echo "| === FAILURE === |"
echo "+-----------------+"
echo
beep -f 440 -l 500;
beep -f 220 -l 500;
exit 1
} fi
} else {
echo
echo "Cancelled"
echo
exit 0
} fi

10  Using Arduino / Programming Questions / Re: SPI MISO-MOSI arduino on: April 03, 2014, 10:48:51 am
@tmd3
Quote
data2 is a byte; it's only 8 bits long.  When you right-shift it by 8 bits, there's nothing left.  After this operation, data2 will always be 0.  Is that what you wanted?

Yes  you are right, I just miscalculate it...Thanks! smiley

@krupski
It seems logical for me. Thanks! This is much better explanation then most of the example shown in the arduino example.

I tried to implement the code, but I kinda got a funny results...

So this is how i finally improved my reading function:


I wouldn't use the word "improved" since you did it all wrong. Specifically why did you RIGHT shift the data? All that did is drop bits off the end to fall into the bit-bucket.


OK now, upon looking at the data sheet for your device, I see that it transfers 32 bits at a time.

The top 8 bits are an address, the bottom 24 bits are data.

The pin called "SPI STE" is the device select pin, and it's polarity is active low.

The SCLK idle state is "low" and data is transferred on the rising edge, therefore it is using SPI mode 1 (one).

You need to connect it to the SPI pins of the Arduino and connect the SPI STE pin to the Arduino SS pin.

Then you need to initialize the SPI code to use Mode 1, MSB first and choose an SPI clock of clk/4X (clk/2X will probably work according to the data sheet, but it's cutting close, so go clk/4X to be safe).

Try this code. Note that I can't test it since I don't have your chip available to me. Note that the DIRECTION that you shift bits is important. If you reverse that direction in an effort to "improve" the code, then don't complain when it doesn't work. If you use "shiftout" instead of SPI in an effort to "improve" the code, then don't complain when it doesn't work.

Again, note that this code should be CLOSE, but I don't know if it works because I can't test it here. And note you need to include the SPI.h library and initialize the SPI correctly before using it. I'm not going to write the WHOLE PROGRAM for you.

Code:
uint32_t pulseox_read (uint8_t address)
{
    uint32_t data = 0;
    digitalWrite (spi_ste_pin, LOW); // enable device
    SPI.transfer (address); // send address to device
    data |= (SPI.transfer (0) << 16); // read top 8 bits -> data
    data |= (SPI.transfer (0) << 8); // read middle 8 bits -> data
    data |= SPI.transfer (0); // read bottom 8 bits -> data
    digitalWrite (spi_ste_pin, HIGH); // disable device
    return data; // return with 24 bits of read data
}

void pulseox_write (uint8_t address, uint32_t data)
{
    digitalWrite (spi_ste_pin, LOW); // enable device
    SPI.transfer (address); // send address to device
    SPI.transfer ((data >> 16) & 0xFF); // write top 8 bits
    SPI.transfer ((data >> 8) & 0xFF); // write middle 8 bits
    SPI.transfer (data & 0xFF); // write bottom 8 bits   
    digitalWrite (spi_ste_pin, HIGH); // disable device
}

Lastly, note that if you run this code without the device connected, you will get random data returned to you (whatever state the SPI pins happened to be in at the time). Testing the code without the device connected and assuming you will get a zero in return is a false assumption. The only to test if it WORKS is to connect the device.

Good luck.
11  Using Arduino / Programming Questions / Re: Bug with character arrays on: April 02, 2014, 11:58:00 am
Ok, I figured out what was happening

1st -- the value of 0 shows up as a space when you print it! I wasn't aware of this "feature" before. So you are right, the second value was a zero... but you are wrong that I initialized it that way.
2nd -- I should have included the above code. The code was txt = "0 12". However, I was using a function which modified the buffer.

Here is where it gets interesting. Once I modified the buffer of a constant character array... very few of the character arrays after it would work! This was happening even if I reset the pointer to "0 14" or something similar -- that second value would be always taken as 0.

I think there is something funny in the compiler (probably to save space) where you absolutely should not modify a constant character array -- once you do, you can never again know what ANY constant character arrays do!

Thanks for your help guys.

Without seeing your code, my guess is that Print (Print.cpp in the Arduino core) sees your text[] array as a string and is trying to print it as such, starting from the "offset" you gave it.

For example, imagine this:

const char *string = "hello there";
Serial.print (string[1]);

You think you would get "e", but you get "ello there". To get the result you want you have to typecast the string to tell Print what you want it to do:

Serial.print ((char) string[1]);

...will result in it printing "e".

Make sense?
12  Using Arduino / Programming Questions / Re: SPI MISO-MOSI arduino on: April 02, 2014, 11:48:12 am
Hey Krupski,

Thanks for your complete reply!
I also previously thinking about using the SPI that is already build in the arduino and using SPI.transfer();
However, I just do not understand how the SPI.transfer() function can notice whether the arduino is about to send the bit
or to receive the bit?
While in my system, I want the MISO pin to be able to read the digital value from AFE4490. I am worried that if I used this function, it will sending the bits from the chip instead of collecting the bits.

I'm just not sure about this, so for safety purpose, I use the shiftOut/shiftIn.
Perhaps you could enlighten me about this?

Thank you soo much.


Stella


SPI transfers do both sending and receiving. If you are sending a "write" type of command to the slave device, it reads the data clocked in on the MOSI pin. It may or may not drive "valid" data out to the MISO pin, but that doesn't matter.

If you do a read of the device, IT drives data bits out to the MISO pin which the SPI port "assembles" into an 8 bit byte.

To WRITE to a device, you do this:

Code:
    read_data = SPI.transfer (write_data); // content of "read_data" is irrelevant.

To READ from a device, you do this:

Code:
    read_data = SPI.transfer (write_data); // value of "write data" is ignored


As a more "realistic" example, imagine wanting to get the hour value from an imaginary real time clock chip and then writing a new value to the minutes register:

Code:
// clock chip control bit defines
// bit   7   6   5   4   3   2   1   0
//      R/W  W   M   D   Y   H   M   S
// note: R/W: 0=write, 1=read
// note: W=day of week, 0=sunday
// note: M,D,Y,H,M,S=month,day,year,hour,minute,second
// (good practice to document important stuff in your code)

    uint8_t cmd; // command byte
    uint8_t data; // data byte

    // example: read the year from the RTC
    cmd = 0b10001000; // read, year
    digitalWrite (chip_select, LOW); // enable rtc
    SPI.transfer (cmd); // send command to rtc (read year) (reply is irrelevant)
    data = SPI.transfer (0); // read year reply from rtc
    digitalWrite (chip_select, HIGH); // disable rtc

    // example: write the minute to the RTC
    cmd = 0b00000010; // write, minutes
    digitalWrite (chip_select, LOW); // enable rtc
    SPI.transfer (cmd); // send command to rtc (write minutes) (reply is irrelevant)
    SPI.transfer (58); // write "58" to the rtc minutes register (reply is irrelevant)
    digitalWrite (chip_select, HIGH); // disable rtc

Make sense?
13  Using Arduino / Programming Questions / Re: SPI MISO-MOSI arduino on: April 02, 2014, 07:15:47 am
Hey All,
Currently, I am making a pulse oximetre using AFE4490 by Texas Instrument and arduino Mega 2560.
I have a problem relating to the SPI communication in arduino.
This SPI communication is required to make a writing and reading register module.
So, I am making its function for both writing and reading register. The writing seems good, but the reading might be confusing for me.

Please suggest me how to do this.
Thank you in advance!

Stella

The Arduino boards have built in SPI interfaces you know? You don't need to shift out data manually. Just use the SPI pins and the SPI library.

You would simply access the chip like this (pseudo code - example assumes 24 bits of control / address and 8 bits of return data):

Code:
#include <SPI.h>

    uint8_t control_data_hi_byte = (whatever);
    uint8_t control_data_mid_byte = (whatever);
    uint8_t control_data_lo_byte = (whatever);
    uint8_t result; // return data will go here

    digitalWrite (chip_select, LOW); // activate device chip select (may be active high - check docs)
    SPI.transfer (control_data_hi_byte); // send control / address bits
    SPI.transfer (control_data_mid_byte); // send control / address bits
    SPI.transfer (control_data_lo_byte); // send control / address bits
    result = SPI.transfer (0); // dummy 0 is ignored, data is read
    digitalWrite (chip_select, HIGH); // de-activate device chip select (may be active high - check docs)

Or, if you don't care about speed, want to use ANY pins for SPI and bit-banging is OK for you, you can use code like this (equivalent to "SPI.transfer()" above):

Code:
// transfer one byte via SPI Mode 3
uint8_t spi_transfer (uint8_t data)
{
    uint8_t bits = 8;
    while (bits--) {
        digitalWrite (_sck_pin, LOW);
        digitalWrite (_mosi_pin, data & _BV (bits) ? HIGH : LOW);
        digitalWrite (_sck_pin, HIGH);
        digitalRead (_miso_pin) ? data |= _BV (bits) : data &= ~_BV (bits);
    }
    return data;
}

This code transfers data using SPI mode 3. To do modes 0, 1 or 2 you need to change the order of SCK low/high or high/low, and change whether the sck pin is changed first or the digital read/write is done first. See the attached image for determining which mode you need.

Hope this helps.
14  Using Arduino / Project Guidance / Re: 24bit SPI word size for AD5686 Chip on: April 01, 2014, 08:13:01 pm
Dear HugoPT,
I appreciate your help and thank you.  smiley
However I don't think that solution may work.  Here is the timing diagram provided in the data sheet.

That timing diagram is for reading and daisy-chaining devices. You want the diagram for WRITING.
15  Using Arduino / Project Guidance / Re: 24bit SPI word size for AD5686 Chip on: April 01, 2014, 08:11:10 pm
Hi all,
I have a DAC , AD5686. It requires 8bit registry address and 16bit data send via SPI. (24 all together)

http://www.analog.com/en/digital-to-analog-converters/da-converters/ad5686/products/product.html

How can I do this, since default SPI size is 8 ?
Please help. Thanks in advance.
Gayan

Data is clocked on the falling edge of SCLK. So you need to set the SPI mode accordingly.

The SYNC pin on the device seems to be the device select (i.e. the SS pin).

The command to be sent and which DAC it goes to is determined by the first byte. So, to send data to the part, you would do this (pseudo-code):

Code:
    uint16_t dac_data = (whatever)
    uint8_t high_byte = dac_command << 4;
    uint8_t high_byte |= dac_address;
    uint8_t mid_byte = dac_data << 8;
    uint8_t low_byte = dac_data & 0xFF;
    digitalWrite (sync_pin, LOW); // begin transfer
    SPI.transfer (high_byte); // send command + DAC address
    SPI.transfer (mid_byte); // send DAC value hi byte
    SPI.transfer (low_byte); // send DAC value, lo byte
    digitalWrite (sync_pin, HIGH); // end transfer

Make sense?
Pages: [1] 2 3 ... 45