Show Posts
Pages: [1] 2 3 ... 26
1  Using Arduino / Programming Questions / Re: Send integer get 256. Arduino I2C comunication on: September 16, 2014, 10:39:59 pm
"SLAVE" code doesn't compile.  Is this really the code you're using?
2  Using Arduino / Project Guidance / Re: Help with serial input on: September 15, 2014, 11:40:30 am
You'll get better results if you follow these guidelines about posting your code:
  • Post code.  You did that; good job.
  • Post a complete sketch.  I should be able to copy your code into the IDE, and have it compile.  This code is a snippet - part of a program that won't compile without some additional lines.  If you post a complete sketch, a reader can copy, paste and try it without a whole lot of effort.  If you don't, at least some readers will skip to the next post, and won't respond to yours.
  • Post the smallest sketch you can come up with that illustrates the problem you've encountered.  It's important to post a complete sketch, but it's also important to isolate the issue to a small, easily readable sketch.  If the code is too long and complex, a reader may again skip to the next post.  Your snippet, and the code that I can extrapolate around it, isn't long or complex.  But, if you stay with this activity long enough, one day it will be, and you'll get more and better answers if you're willing to isolate the issue to a small sketch.
  • Post your code in [ code ] tags.  Here's a description of how to do that:  http://forum.arduino.cc/index.php/topic,148850.0.html.  See item #7.  As a new poster to this forum, you'd do well to read the whole thing.  This information is accessible from first sticky post, at the top of the first page of any section of the forum.  As for code tags, they tell the server's software to display each character exactly as it is, rather than interpret some strings of characters as special characters, or display instructions.  That ensures that your code shows up correctly, and isn't garbled.
Some of that has already been said in this thread.  I think that repeating it won't hurt anything.  Please note that, for any of these guidelines that you might not have followed in your initial post, no apologies are necessary, expected, or even desired.

Looking at your code, here's what I see right away:  something is peculiar about this line:
Code:
  float temp;, c;
It looks like there's an extra character in the declaration.  That may be an artifact of not using code tags, but intuitively it looks like real code.  That line gives a compiler error, leading me to believe that this code wasn't copied directly from a sketch that compiled and ran.  It's important that the code you post is precisely the code you used; otherwise, everybody wastes time solving problems that don't exist in your actual sketch.

Looking further, I don't see that variable c ever gets a value.  Yet, it's used in this calculation:
Code:
f= (c*9)/(5)+32;                                //do math
Did you meant to reference variable temp in this calculation, rather than c?

I'll comment on the comment in this line:
Code:
float f ;                                                // Declared and Initialized
Variable f is local to loop().  Local variables aren't initialized when they're declared.  They have a value that depends on whatever was already in their memory location - it could be anything.  The comment doesn't affect your sketch, but it suggests that you expect these local variables to be initialized, and they aren't. 

Finally, I'll note that Serial.parseFloat() takes characters that make sense as a floating point number - digits, decimal point, minus sign, and plus sign.  It leaves any other character it finds in the buffer.  If your serial monitor is set up to send a newline or carriage return, then the next time loop executes it will find that character in the buffer, try to parse a float from it, and return a zero.  I would expect that you'd see the program print a "32" as a second line for each entry.  You can set the serial monitor to send nothing after the input, and that will work.  Or, you can use Serial.peek() to look at the buffer, and then read characters off the buffer until the first character is something that makes sense as a float.
3  Using Arduino / General Electronics / Re: 555 resistor value for Tm = Ts on: September 14, 2014, 09:42:32 pm
TI's datasheet for the 555 describes how to get a 50% duty cycle.  See this link, page 12:  http://www.ti.com/lit/ds/symlink/lm555.pdf.  If a precise 50% duty cycle matters, you'll be better off running the 555 at twice the frequency you need, and clocking an external flip-flop with the output.  Otherwise, the formula in the datasheet will get you close.
4  Using Arduino / Programming Questions / Re: Convert two integers to a long on: September 14, 2014, 05:35:04 pm
Your subject sounds like you want to perform some kind of operation on two integers, with a long result.  The content of your post sounds like you want to convert a single integer to a single long.

Can you tell us, specifically, what you really want to do?
5  Using Arduino / General Electronics / Re: Running batteries in parallel and still getting power with negative disconnected on: September 10, 2014, 09:24:51 am
Yes, a schematic, and maybe a picture of the batteries and the conductors connected to them, too.  And tell us exactly why you think that you "still getting power."  If you're measuring something, tells us exactly where you're measuring, and exactly what the readings are.

Our impression is that you believe that power flows to the load with the negative terminal of the paralleled batteries disconnected from the load.  That may not be what you intend to report.  It may be that you're measuring the current at one of the batteries' negative terminals.  If that's so, then you're measuring current flowing between the batteries.  Not unexpectable; it's almost certain that their voltages aren't precisely equal, and, with the very low impedances involved, a little bit of voltage difference will give rise to a noticeable current.
6  Using Arduino / Project Guidance / Re: rms Voltage on: September 08, 2014, 12:24:41 am
Code:
(unsigned long)( adc_raw * adc_raw)
does not give the same result as
Code:
(unsigned long) adc_raw * (unsigned long)adc_raw
I don't know why.  It just doesn't on the uno. 
It's because the Uno uses 16-bit integers, and the values of adc_raw are bigger than 8 bits, so their product overflows an integer calculation on the Uno.  adc_raw  is type int, so the calculation is dutifully carried out with integer math. When the result is bigger than 16 bits, the calculation overflows and information is lost.  The reason that it doesn't work on the Uno, and might on some other platforms, is that Uno integers are 16 bits, and they're bigger on some other machines.

I'd prefer to cast adc_raw as long, since it clearly takes on negative values.  The calculation yields the same result either way, on account of the miracle of two's complement arithmetic, but I'm more comfortable closer to the mathematical realities of the problem.

The other thing that rankles about the original program is the nominal sample rate at 1 per 100 us.  A standard analogRead() takes a bit longer than that, so the timing will always be off.
7  Using Arduino / Programming Questions / Re: Problems using Adafruit RGB LCD Shield on: September 07, 2014, 11:17:11 pm
OK, when I try your code, as posted in the original post, with the library properly installed, it compiles without complaint.  So, I think that there's some quirk in the way the library is installed on your system.  Mine has all of the *.h and *.cpp files, and keywords.txt.  That's this list:
  • Adafruit_MCP23017.cpp
  • Adafruit_MCP23017.h
  • Adafruit_RGBLCDShield.cpp
  • Adafruit_RGBLCDShield.h
  • keywords.txt
That's everything except the example, the ReadMe file, which seems to be some kind of an advertisement, and the license file.  To install the library, I followed the instructions, quite precisely, that are linked from Adafruit's product page for installing libraries.  I'm using Ubuntu 14.04.
8  Using Arduino / Programming Questions / Re: Problems using Adafruit RGB LCD Shield on: September 07, 2014, 08:58:15 pm
Something is peculiar about those library files.  I'm not sure what they were thinking, and I certainly didn't intend that you delete the #include directive for "Adafruit_MCP23017.h" and replace it with "Adafruit_MCP23017.cpp".  But, looking at the library, that seems to be how you have to do it.  I still can't see anything that includes "Adafruit_RGBLCDShield.cpp," so you may ultimately have to include it explicitly.  But, try what I suggest below, and we'll see what happens after that.

The errors that you report - the compiler seems to be unaware of the definitions of some fundamental data types - seem to be related to a quirk of the IDE.  Try moving this statement
Code:
int coins;
to the top of the sketch.  I think that there's something peculiar about the way that the IDE processes its own included files - that it puts them right after the first statement in the sketch that isn't a comment or a compiler directive.  So, the code that defines uint8_t and uint16_t is included somewhere below the earlier included files, and, wherever they reference those types, the compiler throws an error.

At least, I think that's what's happening.  There are others in this forum that can describe the issue in detail, and I hope they chime in.
9  Using Arduino / Programming Questions / Re: Serial read -> LCD print issue on: September 07, 2014, 08:17:44 pm
Show a schematic of your hardware.  There's no way of telling what's wrong without that information.

Except, maybe, for this: 
Code:
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
SoftwareSerial mySerial(10, 11); // RX, TX
These two lines assign pin 11 as the enable pin for the LCD, and as the TX pin for the software serial object.  Pin 11 seems almost certain to fail at one of those tasks.
10  Using Arduino / Programming Questions / Re: Problems using Adafruit RGB LCD Shield on: September 07, 2014, 08:04:37 pm
I'm going to guess that you downloaded and installed the file, "Adafruit_RGBLCDShield.h," but didn't do the same with "Adafruit_RGBLCDShield.cpp."  Your error messages show a reference to Adafruit_RGBLCDShield.h, which makes me think that particular library is available.  The error messages say that the compiler doesn't know how to build an "Adafruit_RGBLCDShield" object, and that makes me think that the corresponding .cpp file is absent.  I can't verify it, but I'll bet that "Adafruit_MCP23017.cpp" isn't available on your computer, either.

11  Using Arduino / Audio / Re: Help with audio quality! on: September 07, 2014, 08:42:24 am
Tell us these things:
  • How are you connecting to the amplifier input?  Tell us everything in the circuit between the sound module and the amplifier.  A schematic drawing would be best.
  • What results did you get when you connected the amplifier input between PWM and GND?
  • What results did you get when you connected the amplifier input between SPK+ and GND?
  • What is that amplifier?  A self-contained bit of consumer stereo equipment, an LM386, or something else?
12  Using Arduino / Audio / Re: Help with audio quality! on: September 01, 2014, 05:37:55 pm
suppose I viewed SPK- and GND as the same net
My take is that SPK+ and SPK- are complementary PWM outputs, that deliver pulses in a fashion that keeps the time-average voltage across the speaker at or close to zero.  A speaker coil doesn't like a DC voltage across it:  as an inductive load, it'll draw more current at DC than it will at AC; and a DC voltage will drive the coil to some off-center point, leaving it less throw on one side.  And, probably some other things that I don't know about.  An amplifier typically likes to see a voltage that varies back and forth around ground.

There's a circuit shown in the datasheet, accessed from the Sparkfun product page, that claims to describe the MP3 mode for an external amplifier.  I can't see how it differs from other modes, so I'm uncertain about how the MP3 mode is selected, or it there's any requirement to select it specifically.  A lot of would-be users of devices like this one have posted about it in this forum.  Some find them nearly intractable, while others get good results easily.  I can't see what the magic bullet is.

[Edit: Fixed punctuation]
13  Using Arduino / Audio / Re: MCP4922 problem on: September 01, 2014, 04:47:51 pm
OK, so it looks like this:

MCP4922   PIN        CONNECTED
PIN       FUNCTION   TO
-------   --------   ---
 1        VDD        5V             
 2        NC         ---             
 3        CS         DUE PIN 10 (CS)         
 4        SCK        DUE ICSP-3 (SCK)
 5        SDI        DUE ICSP-4 (MOSI)
 6        NC         ---             
 7        NC         ---             
 8        LDAC       GND
 9        SHDN       5V
10        VOUTB      -> DAC B OUT
11        VREFB      2.5V - RESISTIVE DIVIDER
12        VSS        GND
13        VREFA      2.5V - RESISTIVE DIVIDER
14        VOUTA      -> DAC A OUT

Changes I've made to your list:
  • Added the Due pin number for CS that corresponds to your code, pin 10.
  • Added the Due ICSP designations for those pins.
  • Added a connection between MCP4922 9, SHDN, the shutdown pin, and 5V.  If that pin is left open and read by the MCP4922 as a low input, the DAC shuts down.  If you don't use that pin, it should be tied high.
It's worth noting that you can use the same resistive divider to supply VREFA and VREFB.  You may well have done it that way; I mention it for completeness.

Here's something else to note:  The MCP4922's datasheet shows VIH, the minimum voltage that the circuit promises to read as high, as 0.7VDD.  That's 3.5V.  The Due's logic outputs can only be as high as 3.3V, and that's less than VIH.  There's a possibility that the MCP4922 will not be able to see a high input from the Due, and will thus give unexpected results.  It's not particularly likely, as 3.3V is pretty close to VIH, but it's not impossible for the MCP4922 to read lows where it should see highs under some conditions, and for some unlucky MCP5922's to never read a high in this circuit.  If you start getting unexpected results, that's a possible reason.  A remedy would be to apply some level-shifting between the Due and the MCP4922

With LDAC grounded, the input registers transfer immediately to the DAC output when they're received.  It's easy, but the DAC is less functional in that mode.  The purpose of LDAC is to allow synchronization of the A and B outputs, and other DAC's as well, if the device has others.  You can load register A, load register B, then pulse LDAC, and both outputs will update simultaneously.  You can also use LDAC for hardware-controlled timing, by loading the A and B registers, and letting a hardware timer output control the LDAC input.  The outputs update precisely on the clock, and you can load the next values into the registers in response to the timer, by polling or interrupt. 

Note that the function of the LDAC pin is controlled by bit 14 of the input message:  if that's a 1, LDAC is active; if it's a 0, LDAC has no effect, and the DAC register transfers to the output immediately.  Your code sets bit 14, so LDAC is active.
14  Using Arduino / Audio / Re: Help with audio quality! on: August 31, 2014, 06:06:59 pm
Is the DCLK pin the DAC output ? I didn't notice that.
I don't think so.  It looks like the datasheet describes two different modules - WTV020-SD-16P and WTV020-SD-20S - that use the same IC, WTV020SD-20S.  The '-16P module has an output labeled, "AUDIO-L," which appears to be a DAC-ish output.  The '-20S module doesn't have that output.  Comparing the schematic linked to the Sparkfun product page with the schematics shown in the datasheet for both modules, the Sparkfun unit doesn't look like either one, but the functionality provided by the outputs at the card edge seems to resemble the '-16P.  The AUDIO-L output comes from pin 10 in the IC, and, based on the Sparkfun schematic, that's connected to a pin called, "PWM," on JP-2 Pin 1.  The datasheet shows this pin and GND as the output to an external amplifier, in the MP3/DAC output mode. 

I don't know what mode the OP is using.  I don't find clarity in the datasheet about how to select the various modes, if one actually selects them.

The blurb lists this as a feature:
Quote
Dedicated 16-bit DAC/PWM audio output to use with an external amplifier.
The datasheet, on page 20, shows this heading
Quote
8.4.MP3 MODE APPLICATION CIRCUIT(DAC OUTPUT)
, with this note shown in the text
Quote
WTV020-SD-16P DAC output,” Audio L” and module GND to amplifier. WTV020-SD-20S DAC output, “SPK+” and module GND to amplifier.

How is the external amp connected to the module when it's delivering lousy sound?  The datasheet suggests driving an external amplifier from SPK+ and GND, and calls it a "DAC output mode" for the WTV020-SD-20S, whcih doesn't bring pin 10 of the IC to a connector.  I don't know how the OP's amp is connected.  If SPK+ and SPK- are used as input to the amp, I'd expect trouble.  There'll be less trouble with SPK+ and GND, but, until it can be verified, I'd recommend keeping the volume on the amp turned down low, as I'd expect the PWM frequency to be well-represented in the output signal.

A search of the forum finds others having trouble getting the -16P device to work as expected.  Solutions posed include making sure to format the microSD to FAT16.  There's talk of fiddling with the SD card - apparently, not all of them are compatible - and of using a different supply voltage, but those suggestions appear to refer to module '-16P, which can use a standard non-mocro SD card.  The OP seems to be getting his micriSD to work already.
15  Using Arduino / Audio / Re: Help with audio quality! on: August 31, 2014, 09:46:46 am
For this Sparkfun Audio-Sound Breakout - https://www.sparkfun.com/products/11125 - the blurb and datasheet both reference a DAC-based output for connection to an external amplifier.  If you're using this device with the PWM output connected to the amplifier, try connecting the DAC output instead.  If you're already using the DAC output for the amplifier, then the audio quality issues you mention may be related to the device's 4-bit format.  If you're not using this device at all, but some other one, just forget I said anything.

Maybe you could mention exactly what device you're using, and either post a schematic or give us a list of your connections?
Pages: [1] 2 3 ... 26