Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: Can someone tell me what I am doing wrong? on: October 03, 2011, 07:22:45 am
I usually only use brackets for multiple things like:

if (1 = 1) (doSomething());

...but if I need multiple things I use brackets like:

if (1 = 1){
doSomething();
doSomethingElse();
}

It seems to get the same result, and doing it that way I never confuse ( for {.

Just to confirm, these two statements are identical, right?
if (1 = 1) (doSomething());
if (1 = 1) {doSomething();}
2  Using Arduino / Programming Questions / Re: Can someone tell me what I am doing wrong? on: October 03, 2011, 06:03:56 am
Video of what I have so far...

3  Using Arduino / Programming Questions / Re: Can someone tell me what I am doing wrong? on: October 02, 2011, 11:35:49 pm
First, let me appologize for how the code looks in the link...I have not done ANY optimization whatsoever...I am trying to get it working before I do that so I know if there are any issues after optimization I know they are from optimization and not from my starting point.

robtillaart - I will have to read up on map...I never even heard of it as I am an extreme beginner at all this (I am sure that was obvious from the liberal use of "IF" statements).  I copied your SetFan() function to my sketch, deleted the extra parentheses, and it works.  I don't quite understand how it works yet, but it does work, so you have my sincere thanks.  I'll make sure to give you credit for that function in future revisions of the source code (don't worry...I won't give you credit for the rest of my mess of a program)

DC42 - The values of maxTempC and minTempC are set by the user.  This is version 1.2, version 1.0 didn't work and version 1.1 just had maxTempC, with minTempC locked to 10C lower.  The value range of maxTempC is 10-85 and the value range of minTempC is 10-75 (and if minTempC is ever higher than maxTempC due to incorrect settings, it just sets the fan to about 96%).

jwatte - I need more than 3 steps.  From previous experiments with this fan, 12 steps is the least I can get away with without the fan changing speed so quickly that it is like a reving engine.

This forum is great...hopefully one day I will know enough about all of this to give something back.
4  Using Arduino / Programming Questions / Re: Can someone tell me what I am doing wrong? on: October 02, 2011, 01:07:37 pm
Thanks for the reply.  I'm afraid I don't quite understand...when I replace parentheses with braces the code fails checks.  The only ones I can change are the single-line commands at the ends of the "IF" statements...and I tried that; it made no difference.  As soon as the temperature hits the minimum, the fan goes from 28% to 86%.

I thought I had posted just the part that is giving me problems...that is, the function that determines the fan speed based on the temperatures read and the "minimum" and "maximum" temperatures set by the user.  Are you saying that you think it is something elsewhere that is causing these issues?

Also, what did you mean by, "an unexplained in version"?

BTW...this code is being run on a Teensy 2.0++, just in case you were wondering why there were 8 temperature readings.
5  Using Arduino / Programming Questions / Can someone tell me what I am doing wrong? on: October 02, 2011, 11:34:41 am
I'm having some issues with a sketch I wrote for a fan controller using temperature sensors.  The problem is that the fan curve is all screwed up...it goes from minimum speed to maximum speed and it skips all the steps in between.  The code is too long to post (the forum won't let me)...so I am just posting the function that sets the fan speed.  What do I need to change?

Code:
void SetFan(){                                                                       ///
  if (minTempC > maxTempC) (analogWrite(FanPin, 250));                               ///
  else{                                                                              ///
                                                                                     ///
  if (CTempArray[6] >= CTempArray[7]) (highestReading = CTempArray[6]);              ///
  else (highestReading = CTempArray[7]);                                             ///
                                                                                     ///
  degreeSeperation = (maxTempC - minTempC);                                          ///
  degreePerStep = (degreeSeperation / 12);                                           ///
                                                                                     ///
  if (highestReading >= maxTempC) (TMP07 = 250);                                     ///
  else if (highestReading >= (maxTempC - degreePerStep)) (TMP07 = 235);              ///
  else if (highestReading >= (maxTempC - (2 * degreePerStep))) (TMP07 = 220);        ///
  else if (highestReading >= (maxTempC - (3 * degreePerStep))) (TMP07 = 205);        ///
  else if (highestReading >= (maxTempC - (4 * degreePerStep))) (TMP07 = 190);        ///
  else if (highestReading >= (maxTempC - (5 * degreePerStep))) (TMP07 = 175);        ///
  else if (highestReading >= (maxTempC - (6 * degreePerStep))) (TMP07 = 160);        ///
  else if (highestReading >= (maxTempC - (7 * degreePerStep))) (TMP07 = 145);        ///
  else if (highestReading >= (maxTempC - (8 * degreePerStep))) (TMP07 = 130);        ///
  else if (highestReading >= (maxTempC - (9 * degreePerStep))) (TMP07 = 115);        ///
  else if (highestReading >= (maxTempC - (10 * degreePerStep))) (TMP07 = 100);       ///
  else if (highestReading >= (maxTempC - (11 * degreePerStep))) (TMP07 = 85);        ///
  else (TMP07 = 70);                                                                 ///
                                                                                     ///
  TMP08 = (lastFanSpeed * 31);                                                       ///
  TMP09 = (TMP08 + TMP07);                                                           ///
  lastFanSpeed = (TMP09 / 32);                                                       ///
  if (lastFanSpeed > 254) (lastFanSpeed = 254);                                      ///
                                                                                     ///
  analogWrite (FanPin, lastFanSpeed);                                                ///
  }                                                                                  ///
}                                                                                    ///

BTW...I uploaded the whole code to my website here: http://www.killerbug.net/TEMPSHARES/PS3_Slim_Sketch_v12_working_except_fan_curve.pde
6  Using Arduino / Project Guidance / Re: How do I mix i2c voltages? on: September 18, 2011, 11:09:57 am
The fan motor is 12V, the PWM pulses are just to control speed; almost no current load.  In retrospect I really should have used a more simple method...I have an attiny45, a cap, and a resistor to do the job (I needed the 3.3v regulator for other parts of the project anyway), and I guess I could have done it with just two resistors and a zener diode for safety.

It is actually:
5V (pulse peak) PWM never going over 67% > PWM to analog conversion by resistor and cap > 3.3v analog to PWM converter.

Now that I think about it, the i2c idea was REALLY dumb...but now that I know how to make 5V and 3.3V i2c play together, I can wire up the RTC that way (it works with 5.0v but they recommend 3.3v)...and the next time someone searches for it on google, hopefully this thread will come up.
7  Using Arduino / Project Guidance / Re: How do I mix i2c voltages? on: September 18, 2011, 04:29:14 am
Much easier to reduce the PWM voltage I would think.

______
Rob

I'll have to try a voltage divider on the i2c signal pins.

As for reducing the PWM peak voltage...would this be by external means like a zener diode, or is it possible to do this with code?

I've already gotten around the i2c for this project by attaching a 4.7K resistor and a 1UF cap to the PWM output from the arduino, so that the AtTiny gets an analog input of 0-3.3V, and then it converts that to a PWM voltage with 3.3V peaks.  This reduces the usable PWM scale from 0-255 to 0-169, but that is still enough for this project.
8  Using Arduino / Project Guidance / How do I mix i2c voltages? on: September 18, 2011, 03:12:22 am
I am building a project around a Teensy 2.0++ using Arduino for programming.  It is running on 5.0v in order to keep the clock at 16MHZ.  One of the devices that is being controlled is a fan motor with PWM control.  However, the specs on this fan say that the maximum pulse voltage must be no more than 3.6V.  This is a funny sized fan so replacement isn't an option.  I figured that the best way to address the problem would be to program an ATtiny45 as an i2c slave, and run that on 3.3V.  The problem I encounter is that i2c doesn't exactly play nice like this.  The "low" pulses from the Teensy are over 3.3V even without pullup resistors.  Does anyone else have a trick for this?  I know there are other ways to go about this particular goal, but now that the question is in my mind, I must learn how to mix i2c voltages!!!
9  Forum 2005-2010 (read only) / Syntax & Programs / Re: Integrate Hex into sketch? on: September 30, 2010, 05:46:55 am
A simple decompiler would do the job regardless of any arduino hardware limitations...if there really is no such beast for the arduino, I might scrap my current project and start on that.
10  Forum 2005-2010 (read only) / Syntax & Programs / Re: Integrate Hex into sketch? on: September 30, 2010, 05:07:01 am
I am not doing it because I am a beginner that does not know how do to it...and I was hoping that someone else already did it for me.  I have no question that this can be done...and I am amazed that it has not been done already (actually, I don't believe that at all...I just have not found where it was done in the past)

They can calculate pi to an almost infinite number of places...clearly there is a mathematical formula...it just does not fit into our 10-base system very well.

I am currently traveling faster than light, as the part of the space that I reside in is traveling faster than the speed of light.  This means that with sufficient technology, energy, and knowledge, one could reach any speed...even a speed as extreme as a stop.

There are many things that humans don't yet know how to do...but I strongly believe that nothing is impossible, except an impossibility.
11  Forum 2005-2010 (read only) / Syntax & Programs / Re: Integrate Hex into sketch? on: September 30, 2010, 04:49:56 am
Can't be done?  Can't?  That is a 4-letter word worse than anything banned from TV.  Anything can be done; that is what it means to be human!
12  Forum 2005-2010 (read only) / Syntax & Programs / Re: Integrate Hex into sketch? on: September 30, 2010, 04:05:37 am
I'm afraid that won't work...perhaps I need to be more specific...

The HEX in question allows the arduino to simulate a certain USB device (this is 100% legal by local laws, but I would still rather not go into specifics...I'll just say it is related to the PS3)...when you plug the arduino into the system using the virutal USB port created from pins, the arduino identifies itself as this USB device, issues a few commands just like this device would, confirms that a condition 0 is reached, and then turns on a LED to indicate success...at this point, it is doing nothing; you can even unplug it from the USB at this point.

I want to use this as a function...so that I can write a sketch that does about 10 different things, runs the hex, and then does about 10 different other things, before being dropped to a loop that does a few other things.  Note that while the hex does send a few status updates by serial communication through the onboard USB port, everything I really need it to do is all done through the virtual USB port.
13  Forum 2005-2010 (read only) / Syntax & Programs / Re: Integrate Hex into sketch? on: September 30, 2010, 03:02:03 am
I would if I could; but he posted this hex anonymously; I can't even send a private message via a forum.  I posted a plea for the source to be posted, but got no response.

If this were a PC app, I would just decompile it...but I don't know of any decompilers for Arduino hex files...so I am in a tough place.  I don't want to need to use two seperate arduinos for this single project, and I certainly would not need to if I had source...even if it was the confusing, almost useless source you get from a decompiler.
14  Forum 2005-2010 (read only) / Syntax & Programs / Re: Integrate Hex into sketch? on: September 30, 2010, 02:48:43 am
This particular HEX file only does one thing...it runs a complex script for about 5 seconds, and then it just sits doing nothing until you hit reset on the arduino.  I would like to be able to just encapsulate this 5 second script, so that I could call it like it was a library function.
15  Forum 2005-2010 (read only) / Syntax & Programs / Integrate Hex into sketch? on: September 29, 2010, 10:50:31 pm
Hi, I have got a .hex file with no source.  If flashes just fine, works just fine, but I want to use it as a function within a normal arduino sketch.  Is this possible?
Pages: [1] 2