Show Posts
Pages: 1 ... 3 4 [5] 6 7 8
61  Using Arduino / Programming Questions / Re: How to remain inside a function? on: October 11, 2012, 10:53:39 am
Right, that is why it worked ok in the UNO because it was mostly absolute. It is used only once from Reset so the 0-4 Seconds was just that, minus a small startup time. It doesnt work very well in leonardo because of the way the Serial port works so I am trying to find another way to test the Max and Min.
62  Using Arduino / Programming Questions / Re: How to remain inside a function? on: October 11, 2012, 10:36:13 am
But isn't that what the next 2 IF statements do? Test in the 0-4 seconds for the max value and test in 4-8 seconds for the min value?
63  Using Arduino / Programming Questions / Re: How to remain inside a function? on: October 11, 2012, 09:50:36 am
Hi Paul
Yes this was indeed just a dummy to show the branch requirement, that is why it did not matter about the variable, I just assigned it to a fixed value to see the result of branching without having to use the analog input for decision.
The reason I never need to get back to the main loop is that the application is a sensor that has 2 different data sets depending on the initial startup condition. So if the sensor value is X at startup the program should go to Branch 1 and if it is Y then it should go to Branch 2. Once in a particular branch, there is a calibration routine. For the first 4 seconds I read the sensors max value (with full load) and in the next 4 seconds I read its MIN value (with no load). Once it is calibrated, the sensor is used to make measurements until such time it is turned off, so i never need to get back to the main loop.
I have to find another way to do the calibration step. Below is what I was using which worked fine on the UNO, I guess I will have to use a few FOR loops?

Code:
static int sampleLow = 1024;
static int sampleHigh = 0;

  while (millis() < 8000UL)
 
  {
    if (millis() <4000) {
    lcd.setCursor(0, 0);
    lcd.print("Measure");
    lcd.setCursor(0, 1);
    lcd.print("High");
     Serial.println("Measuring High");
    }
    if (millis() >4000) {
    lcd.setCursor(0, 0);
    lcd.print(" Remove ");
    lcd.setCursor(0, 1);
    lcd.print(" Load");
    Serial.println(" Remove Load");
    delay (200);
  }
   
       
    // MEASURE
    int sensorVal = analogRead(A0);

    // MATH
      sampleLow = min(sampleLow, sensorVal);
      sampleHigh = max(sampleHigh, sensorVal);
}
64  Using Arduino / Programming Questions / Re: How to remain inside a function? on: October 10, 2012, 11:52:40 pm
Ok I think I found my problem. I have a while (millis() < 80000) statement in each of my branch functions  as usually this is the time for the initial calibration of my sensor. I measure the minimum and maximum value of my sensor in this time. Obviously by the time the serial connection is made with the Leonardo the millis is already counting down.
I will have to find another way to delay the calibration feature. This sensor has no buttons or switches that i can use as it just operates when you plug in the USB.
65  Using Arduino / Programming Questions / Re: How to remain inside a function? on: October 10, 2012, 11:36:43 pm
Thank you for the replies. Using the While statement works well. The actual issue i am having is with Arduino Leonardo. My original code runs without problems on the UNO, because the Uno resets when you connect to USB and that allows my sketch to do the analogRead and make the decision between the 2 loops. However the Leonardo does not reset. So I have been trying to troubleshoot it and wanted to make sure of the structure to use function calls.
I have followed the getting started guide for Leonardo and it says I can use the  while (!Serial) ;
statement to do nothing until a serial connection is made. This works when I structure it like the below but somehow when I apply it to my original code, the program just continues to execute even if the Serial Monitor is closed. This means i miss the calibration step in the beginning analogRead.
Sorry, I know it is confusing.
Code:
int i = 1;
//==========================================================================================================//
void setup()
{
  Serial.begin(9600);
  while (!Serial) ;
   }
//================================================================================================//
// Decision between option1 & option2
void loop()

   if (i == 1){
           Serial.println("Option 1"); 
   option1();
 
     } 
 
   else if (i = 2){
          Serial.println("Option 2");
     option2();

    }
  Serial.println("Why?");
}
//===============================================================================================================================================//
void option1()
{
 while (i==1){     
  for (int i=0; i <= 3; i++){
     
      Serial.println(i);
      delay(200);
        }}
}

//============================================================================================//
void option2()
{
      for (int i=10; i <= 13; i++){
   
      Serial.println(i);
      delay(200);
        }
}
66  Using Arduino / Programming Questions / How to remain inside a function? on: October 10, 2012, 09:59:40 pm
I need some assistance to understand structuring my own functions. I can create a function and call the function based on a decision in the void loop() but why does the program return to the loop afterward?
How do I structure it to just remain within the function once it has branched there. I know it sounds silly with this example but basically my application makes a decison between 2 different sets of data to execute based on the initial value of the analog input. Once that decison is made it should remain within the function. So in my example code I branch to option 1 which is executed and I would never expect the Serial.println ("Why?")  statement to be executed but it is.
Can someone explain why and tell me the correct way to structure this?

the output is -
Why?
0
1
2
3
Why?
0
1
2
3
Why?
0
1
2
3
Why?


Code:
int i = 1;
//==========================================================================================================//
void setup()
{
  Serial.begin(9600);
   }
//================================================================================================//
// Decision between option1 & option2
void loop()

   if (i = 1){
   option1();
          } 
 
   else if (i = 2){
     option2();
    }
  Serial.println("Why?");
}
//===============================================================================================================================================//
void option1()
{
      for (int i=0; i <= 3; i++){
     
      Serial.println(i);
      delay(200);
        }
}

//============================================================================================//
void option2()
{
      for (int i=10; i <= 13; i++){
   
      Serial.println(i);
      delay(200);
        }
67  Using Arduino / Programming Questions / Leonardo analogReference options? on: October 10, 2012, 12:39:01 pm
Hi
Does anyone know what options are available for analogReference in the Leonardo? The Atmega328 has an internal reference of 1.1v which I was using but does not work on leonardo.
What are my other options?
Thanks
68  Using Arduino / Microcontrollers / Re: Debugging UNO standalone - Help needed on: June 13, 2012, 09:41:51 am
Thanks, I figured it out. I did it in AVR Studio without all the DFU mode sequences, I just erased the chip and inserted the combined .hex. It would be nice to do it through the usb port but since I am already using AVR Studio to bootload the Atmega328, its just another connection.
The reason I dont use an UNO is seen in the pic. My Uno is about the size of a nano to fit in a specific location for standalone use. When I need a display, it fits onto a motherboard that has switches, inputs and a LCD stacked on top.
Can you tell, I dont like wires? :-)
69  Using Arduino / Microcontrollers / Debugging UNO standalone - Help needed on: June 12, 2012, 01:14:20 pm
I need some assistance figuring what the issue is with my standalone board. This is my second board, the first one was a Nano copy using the FT232RL and worked OK but I was unhappy with the sporadic enumeration of the USB. I redesigned it using Atmega16U2 just like Uno.
I am able to connect USb to the 16U2 and using FLIP I have loaded Firmware (Uno_and_USBSerial_combined.hex) and installed the driver so now it registers as Com port on my PC.
I am able to bootload the 328P using ICSP and AVRISPMK2 and loaded OPTIBOOT (optiboot_atmega328.hex).
I set fusebits as follows
uno.bootloader.low_fuses=0xff
uno.bootloader.high_fuses=0xde
uno.bootloader.extended_fuses=0x05
uno.bootloader.file=optiboot_atmega328.hex
uno.bootloader.lock_bits=0x0F
This all verifies correctly.

problem is when trying to upload a sketch, I get the avrdude: stk500_getsync(): not in sync: resp=0x00 error.

With the scope I can see the reset pulse when uploading, but I do not see any data coming into RXD. It goes low for a second but I never see the data pulses coming in.
The Atmega16u2 is so hard to verify correct connection as the pads are all under the device but I assume it is correct as I can DFU bootload it. I am trying 3 boards so its not likely a solder error.
ANY suggestions of troubleshooting would be appreciated.

70  Using Arduino / Microcontrollers / Re: Another DIY Arduino with PCB on: May 29, 2012, 11:33:38 pm
That sure is a lot of vias you used. Did you use an autorouter? Also see a lot of right angles in your tracks. Not a god idea for noise, but thats just my opinion. Looks good otherwise though
71  Using Arduino / Installation & Troubleshooting / Arduino Nano and Bluetooth issue on: May 20, 2012, 12:49:44 pm
I used a bluetooth module successfully with the Uno, connecting rx-tx as normal and am able to stream data through bluetooth. However when i connect the Bluetooth module to a Nano that uses the FR232RL chip the bluetooth does not work. The USB works of course to the RS232RL but the bluetooth module will not make a connection although it connected to the same lines on the ATmega328 D0(RX) and D1(TX)
Anyone have an idea why this is? Seems like the FT232RL "holds" the com line.
thanks
72  Community / Gigs and Collaborations / Looking for a Mac savvy programmer to port existing .NET application on: May 14, 2012, 05:51:55 pm
I am looking for a Programmer to convert an existing application that I have. It was written for me by Peter Baines as a paid project. I need a Mac version. The original is written in VB.NET and I wouldnt like to pay for a whole new development again. I was thinking if it could be converted to Processing or failing that, a Mac application. The principle is quite simple in that an Arduino streams data via VCP to a computer.
Pm or email me at liam1062@gmail.com if youre interested.
73  Using Arduino / Project Guidance / Migrating from battery power to USB power, advice sought on: May 07, 2012, 08:51:35 pm
I currently produce a product which uses a 9v battery with 5v regulator like an Uno, I use bluetooth with this to send data to PC. I want to produce a version based on Nano that uses USB port for both data and Power.
Problem is the sensor is powered by 5v and its output is obviously dependant on the 5v. I use the internal 1.1v reference. The unit is calibrated for the specific sensor at assembly time.

My question is regarding USB power. I am concerned that the USB power on different computers may vary considerably as the spec is 4.5 to 5.45v I think. Does anyone have experience with this? If my calibration is done on my pc at 5.02v and the users pc only gives 4.8v, the result will be incorrect.

Maybe the USB power should be limited to 4.5v ? Could not use a regulator here, maybe just a zener?
Any advice would be appreciated.
74  Using Arduino / Microcontrollers / Re: Atmega 328 vs 328P Problem on: May 04, 2012, 11:35:06 pm
Thank you
Those settings worked with the ATmegaBOOT_168_atmega328.hex but not with the Optiboot file.
thank you, she now speaks English.
75  Using Arduino / Microcontrollers / Re: Atmega 328 vs 328P Problem on: May 04, 2012, 09:06:43 pm
I tried Optiloader earlier today and now again. Cannot get it to work. I cannot tell if it is programming the board or not as nothing is on the serial monitor. But when I use the programmed board and try to load a sketch, I get an Avrdude error. These problems led me to buy  the avrisp this morning and I am able to burn the bootloader with it. Do you know what the fuse bits should be set to?
Pages: 1 ... 3 4 [5] 6 7 8