Author Topic: Getting started with UNO  (Read 12628 times)

0 Members and 1 Guest are viewing this topic.

OperaHouse

  • Hero Member
  • *****
  • Posts: 1308
  • Country: us
Getting started with UNO
« on: November 16, 2016, 09:48:33 AM »
This thread will cover general issues getting started with UNO.  I wanted someone to start from zero and document every step they did and what problems they encountered.  The only UNO's I have are a real one and several clones made many years ago.  These used the same communication chip.  Now I just use the NANO clones that should not be confused with a real NANO.  Those use the CH340 chip and I had to load the driver off the internet.  There are sites that explain how to do this but they all seem poorly written.  I never documented how I did it, but it took several tries.  At this time there seems to be a deal on ebay.  Search "uno r3 atmega328p" US sellers and one for $2.99 SHIPPED shows up.  This is a full size UNO with the CH340 chip.  It says it will load in the driver automatically.  I have some doubts but at only $3 and getting it in a couple days is worth a try. 

I've been using micros off and on since the late 70.  I don't get too heavily invested in any one as they come and go pretty fast.  Micros are like children.  Every one is different, but they are all the same.  If doing simple logical functions it doesn't matter.  I am still using version 1 of the Arduino and probably should update it.  I'm always concerned they will do something some day to make  the clones incompatible like FTDI did bricking clones.

I demonstrate simple programs in a simple way that I think people will find obvious.  On the internet there are lots of demonstration programs That I think are hard for the novice to understand.  Everyone wants to look like a REAL programmer.  I will write the port number in instead of using a variable name. It will be confusing enough without adding in a bunch of names.

It seems to be the industry standard that every UNO clone come with the sample program BLINK loaded.  Power it up and LED pin 13 will start flashing.  You do not need to use a power supply to make the uno work.  It will use the 5V power from the USB port.   Note the rate of flash because the first thing to do is to change the time delay in the program.   Changing the flash rate of the LED will verify that communication with the UNO was established.  In the tools section you may have to select the board that is being used and the COM port first.   The COM port will usually just pop up on the screen  and it will ask you if that is the poet you want to use.  Sounds complicated already.  I got forced into being the ISO Quality Auditor at a company.  Test procedure had to be written so anyone off the street could come off the street and perform the test, that kind of detail.  On the internet 20 steps are reduced to someone saying just do this.  Your experience will be helpful to others.

If successful with BLINK change, rename the program BASE.  This will become the boilerplate for future programs.  The simple time delay blinking will be changed to a loop counter.  I've found a loop count of 200 convenient to use.  Every line of code takes some time to execute.  The program looping 200 times may take a second or 10 seconds.   Always add in a delay statement of about 20 milliseconds so the blinks will be visible. 

FIRST STEPS

Click on ARDUINO
Then click on FILE
Click on EXAMPLES
Go to BASICS and click on BLINK
The following program will load.

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */

void setup() {               
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(13, OUTPUT);     
}

void loop() {
  digitalWrite(13, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // set the LED off
  delay(1000);              // wait for a second
}

digitalWrite is how you write to a port.  13 is the port number as identified on the board.  This pin has a LED connected to it on the board.  HIGH will send 5V to that pin.  HIGH and LOW are fixed variables representing 1 and 0.  They can not be set to any other value.  Any other variable will have to be named first in the program.  Anything after // is a comment that will help you figure out what the program is doing 6 months from now after you have forgotten.  Use lots of them.

delay(1000)  is the time delay routine.  That number is in milliseconds starting with 1.  1000 is one second.  here is an upper limit we will talk about later.

The } is the end of the program and ; is the end of a line.  Forgetting  the ; will likely be your most common error.  The compiler will point out mistakes, but it generally will be in the line before.

So, change the delay times in both statements from 1000 to 3000. Click on FILE and SAVE AS, then enter the name BASE.  Now does it work?  Move the mouse over to the right arrow in the circle and click.  Two LED on the board will start flashing indicating two way communication.  When finished the pin 13 led will flash at a different rate. (if you are lucky)

Two handy things to have are "male female dupont connectors" or male - male depending on micro.  Depending on the length you can get a large number of these for a couple of bucks.  That will allow connection to modules like this and there will be no need to solder.

http://www.ebay.com/itm/5Pcs-MOS-FET-Button-IRF-520-Driver-Module-For-Arduino-Raspberry-Pi-Perfect-/282178805681?hash=item41b32adfb1:g:STEAAOSwFe5X1-kX

These are limited to 24V and 1A which is pretty small.  I don't know why there isn't a 10A module at 200V.  That would be useful and save you a lot of pitfalls of soldering etc.  If anyone has seen one let me know.  My water heater uses a 36V PV string and I just cut out 6oV FETs from old small UPS supplies.  A hand grinder with a thin cutoff wheel can net you a couple 50A FET heatsink and mounting board.
 

Check back as I will update these posts as I get time and will edit the existing post for the two days that I am allowed.
« Last Edit: November 16, 2016, 02:35:09 PM by OperaHouse »

OperaHouse

  • Hero Member
  • *****
  • Posts: 1308
  • Country: us
Re: Getting started with UNO
« Reply #1 on: November 16, 2016, 12:44:20 PM »
I should have started with the compiler can be found and downloaded at http://www.arduino.org/
Click on DOWNLOAD and then follow instructions.  There is also a GETTING STARTED page.
Comments would be appreciated on your experience with the download process.

Assuming everything works so far, copy this code into BASE.  This is the easy start for any new program.  As you learn other routines such as serial and analogWrite, include those sample lines into the BASE program.  Copy and paste is a heck of a time saver, but it allows you to make mistakes even faster.  The verify check mark circle allows you to compile a program and check for errors without having a UNO connected.  After finding and correcting each error, use the down arrow to save the changes.  Don't feel bad about errors.  I made one error (forgetting the ; at the end of the line) in writing this simple program.

/*
  BASE
  Turns on the LED for a quick blink, then off for a longer period, repeatedly.
  A loop counter counts the number of loopa and resets at 200.
  This boilerplate code for future programs is in the public domain.
  The slash and star indicate multiple lines of comments eliminating
  the need of // before each line.
 */
 
// put additional variable names here.
// int means it is an interger -16K to +16K

int blinktime = 0;    // define blinktime and set initial value to zero

void setup() {               
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards.
  // if you forget to declare an output pin, it will still
  // output a pulse for a machine cycle.  Then the pin will
  // float. That can drive you nuts when driving a FET, but
  // can be really handy at times.
 
  pinMode(13, OUTPUT);   // LED pin declared as an output 
}

void loop() {        // the { indicates the start of the code body
 
  if (blinktime == 200) blinktime = 0;       // reset if high limit is reached
  // this is an interesting line. blinktime == 200, The == is a logical statement.
  // blinktime = 0 A single = is a mathamatical.  Confusing these two is easy to do
  // and will not always show up as an error.  When you have written code that looks
  // perfect but doesn't work, look for this.
 
  if (blinktime == 0) digitalWrite(13, HIGH);   // set the LED on.  It will stay
                                                                // on till it is turned off
 
  if (blinktime == 10) digitalWrite(13, LOW);   // set the LED off when 10 loops
                                                // are reached.  As the program
                                                // increases in size this number
                                                // will have to be reduced
                                               
                                               
  // Between these two lines of code you custom program can be
  // written.  Additional blinks could be included to indicate                                             
  // power level or a low battery warning.  A single blink every
  // second or so is there to indicate the micro is powered and running.
 
 
 
  blinktime = blinktime + 1;    // add one to the program loop count
  delay(10);                          // wait for 10 milliseconds. make shorter
                                          // or longer
}                                         // indicates end of program
« Last Edit: November 17, 2016, 12:33:29 PM by OperaHouse »

OperaHouse

  • Hero Member
  • *****
  • Posts: 1308
  • Country: us
Re: Getting started with UNO
« Reply #2 on: November 18, 2016, 07:56:28 PM »
One of the most common uses of a micro is to read voltages.  That is done with
an analogRead statement. The UNO has six analog pins labeled A0-A5. That function
returns a 10 bit number from 0-1023.  Typically the count should be between 600 and
750.  This prevents you from going over the 5V input limit of the A/D converter. You
often have a lot of noise with the reading.  It is best to average a number of readings
to get a good solid number.  The following code takes a running average and also serves
to multiply the raw A/D reading into a number representing an engineering unit. Note
the new variables had to be added at the beginning of the program.

For a visual, at so many loops the battery voltage is compared with a set value.  The
double && is a logical, it means both statements must be true. You get more blinks as
the voltage gets lower. There is still the single short blink to indicate everything
is OK.

A serial print routine has been added at the end of the program.  It sends data at the
199th loop just before the number resets. The line Serial.begin(9600) tells the micro
at what speed to communicate with, 9600 baud.  Without this line it will not communicate
with the Serial Monitor in TOOLS.  Printing takes time and should be limited in how
much is printed and how often.

Load this program into your computer and save it as an example using these basic functions.
Load it into your micro and do the three following tests:
Jumper A0 to REF......It should read 1023 counts and about 18V.
Jumper A0 to GND......It should read    0 counts and about 0V.
Jumper A0 to D13......It should read    0 counts and about ??V.
Ponder that a while.  It will teach you to be careful in what you believe is happening.

In this sample program the voltage is calculated in millivolts.  In a 12V system that gives a number of about 13,000 or down to the millivolt.  There are two problems with this; (1) with this A/D having a maximum count of 1023 the accuracy is only three digits, more than that is imaginary. (2) With int the number can only go up to 32K. Then it will represent itself as negative.  This becomes a problem over 32V.  Printing all those digits will have the numbers dancing around.  For higher voltages , multiply by a smaller number to give tenths of mv.  In printing notice the word (float).  That formats the number to TWO decimal places after dividing by a thousand which is a reasonable number.

Averaging can almost give an extra digit of accuracy, but it has a slow response.  Sometimes it will be better to use the raw data number when response needs to be fast.  I have mixed both in a program.  The count up and down examples shown later have a slow response.  It is sometimes necessary to add a"clawback" when loads change instantly.

The following POT might be useful while experimenting.  Having soldered connections to a pot is more reliable.
 
http://www.ebay.com/itm/New-Rotary-Potentiometer-Model-Sensor-for-Arduino-UNO-PIC-AVR-MCU-DSP-/282248992879?hash=item41b759d86f:g:IZ8AAOSwA3dYIZmb

/*
  BASEAS
  Turns on the LED for a quick blink, then off for a longer period, repeatedly.
  A loop counter counts the number of loops and resets at 200.
  This boilerplate code for future programs is in the public domain.
  The slash and star indicate multiple lines of comments eliminating
  This program blinks about every second to indicate it is running.
  A/D reads value on A0 then multiplies and averages it to get voltage in mv.
  It blinks more as the voltage lowers and serial data is sent to TOOLS.
 */
 
// put additional variable names here.
// int means it is an integer -32K to +32K
int blinktime = 0;    // define blinktime and set initial value to zero
int rawdata   = 0;    // A0 A/D data
int battery   = 0;    // calculated battery voltage


void setup() {               
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards.
  // if you forget to declare an output pin, it will still
  // output a pulse for a machine cycle.  Then the pin will
  // float. That can drive you nuts when driving a FET, but
  // can be really handy at times.
 
  Serial.begin(9600);         // setup serial and define baud rate
  pinMode(13, OUTPUT);    // LED pin declared as an output 
}

void loop() {  // the { indicates the start of the code body
 
  if (blinktime == 200) blinktime = 0;          // reset if high limit is reached
  // this is an interesting line. blinktime == 200, The == is a logical statement.
  // blinktime = 0 A single = is a mathematical.  Confusing these two is easy to do
  // and will not always show up as an error.  When you have written code that looks
  // perfect but doesn't work, look for this.
 
  if (blinktime == 0) digitalWrite(13, HIGH);   // set the LED on.  It will stay
                                                // on till it is turned off
 
  if (blinktime == 4) digitalWrite(13, LOW);    // set the LED off when 4 loops
                                                // are reached.  As the program
                                                // increases in size this number
                                                // will have to be reduced
                                                                                             
 
  // GET ANALOG DATA AND CONVERT TO BATTERY VOLTAGE IN MILLIVOLTS
  rawdata  = analogRead (0);                    // Anolog In.  Read the battery voltage  PIN #A0  BATTERY
 
  battery  = battery - battery / 18;            // Subtract one average reading   
  battery  = battery + rawdata;                 // Add latest A/D reading back
                                                // 3.3V = about 13500 counts or 13.5V
   
  // Display battery condition by number of blinks
  // First long blink if battery fully charged
  if (blinktime == 60 && battery <= 13750) digitalWrite(13, HIGH);    // set the LED on if below set voltage
  if (blinktime == 70) digitalWrite(13, LOW);           // set the LED off regardless at this time
 
  // Second long blink if battery medium charge
  if (blinktime == 90 && battery <= 13200) digitalWrite(13, HIGH);    // LED on if below set voltage
  if (blinktime == 100) digitalWrite(13, LOW);                 // LED off regardless at this time
 
  // Third long blink if battery low
  if (blinktime == 120 && battery <= 12500) digitalWrite(13, HIGH);    // LED on if below set voltage
  if (blinktime == 130) digitalWrite(13, LOW);                   // LED off regardless at this time
 
  // Fourth long blink if battery discharged
  if (blinktime == 160 && battery <= 12000) digitalWrite(13, HIGH);    // LED on if below set voltage
  if (blinktime == 170) digitalWrite(13, LOW);           // LED off regardless at this time
 
       
 
  // THE FOLLOWING IS THE SCREEN PRINT ROUTINE
  if (blinktime == 199)                         // if on the last count print data
   {                                                   // do everything after the { symbol
   Serial.print(rawdata);                       // A/D value
   Serial.print(" count   ");                    // space, then count, then some more spaces
   Serial.print((float)battery/1000);        // battery voltage TO TWO DECIMAL PLACES USING FLOAT
   Serial.println("V  ");                          // V for volts,  Notice the ln after print.  NEW LINE
   }                                                   // } symbol ends the things to do for this IF
   
  blinktime = blinktime + 1;     // add one count to the program loop count
  delay(10);                           // wait for 10 milliseconds. make shorter or longer to suit
                                 
}                                         // end of program loop
« Last Edit: November 19, 2016, 04:02:29 AM by OperaHouse »

george65

  • Sr. Member
  • ****
  • Posts: 499
  • Country: au
Re: Getting started with UNO
« Reply #3 on: November 18, 2016, 09:22:14 PM »

On your recommendation above, I have bought a couple of the boards. Thought I'd get extra to start with so if I fry one or something doesn't work, I can verify it's the idiot not the machine that is at fault. Cost me all of $4 Au. They must make these things for .50C each. amazing for the power they have.


I'll now look for a kit with all the wires and some shields and bits and pieces to get started learning with.  I'd like to make a solar tracker. Not for a panel but to keep a reflection focused on my neighbours window who built the place illegally and is always looking into my backyard.
Other immediate thing that comes to mind would be a controller for an Oil burner.  This could control fuel flow and maybe air either with a throttle body from a car or chopping the power to the blower motor. I don't know what they are capable of  or more so what I can figure out but i have found that practical projects always teach one a lot more than doing something just for the hell of it.

Seems what you are putting up here is going to be good, practical and useful learning.
Thank you for your efforts and contributions to help others.

OperaHouse

  • Hero Member
  • *****
  • Posts: 1308
  • Country: us
Re: Getting started with UNO
« Reply #4 on: November 19, 2016, 04:07:18 AM »
It is good to have several because it is likely one will be destroyed and one can serve as a test bed to work out the bugs of a software change before the working system is altered.  I would avoid kits  and just buy what you need. If you hadn't noticed the ones with the smaller soldered in processor are cheaper. A replacement micro for the socketed boards is as much as an entire board.

MattM

  • Hero Member
  • *****
  • Posts: 1167
  • Country: us
Re: Getting started with UNO
« Reply #5 on: November 23, 2016, 06:51:08 AM »
Thanks for sharing!  Very good information.

OperaHouse

  • Hero Member
  • *****
  • Posts: 1308
  • Country: us
Re: Getting started with UNO
« Reply #6 on: November 29, 2016, 01:10:51 PM »
                       MAKING A VOLTAGE DIVIDER FOR THE A/D

Measuring voltages with a micro is complicated by the voltages we want to monitor
are generally higher than the A/D limit of 5V. Voltages can be scaled down by use
of a resistive voltage divider.  This can be complicated because it involves some
math and standard values may not be in your junkbox. I've racked my brain for a
simple way to come up with these values. What are we cavemen? The internet always
has someone that will do the work for free. I came up with this website, there are
many others:

http://www.raltron.com/cust/tools/voltage_divider.asp

For any voltage divider you have to know three items to calculate the fourth.  R1
is the upper resistor connected to the battery to be monitored.  R2 is the lower
resistor.  We start with the output voltage going to the A/D.  That can't be more
than 5V.  I choose the voltage of 3.3V for two reasons. (1) That gives a reasonable
count of about 750 for your calculations with some headroom. (2) On the UNO board
there is a 3.3V pin that can be jumpered to. This will allow testing of the software
without connecting the micro into the final circuit.

The input voltage is the normal battery voltage.  Use 13V for a 12V system, close
enough for this example. Now a value for R2 has to be decided.  That usually depends
on what can be found in the junkbox.  A value between 10K and 22K is a good start.
My circuits always have a pot in the middle of the voltage divider with the wiper
going to the A/D.  I use integer math for speed and it is difficult to get the exact
multiplier to get the numbers to come out right.  The value of that pot is usually
between 10% aqnd 25% of R2.  The lower the better for fine adjustment. I have a box
of 5K pots so I use them. 4.7K is the new standard now. Whatever pot you use, take
about 1/2 of that value and add it to your selected R2 resistor.  A 5K pot would give
you 2.5K.  Add the 20K of the lower R2 resistor and the value for R2 in the calculator
is 22500 ohms. Follow the instructions on the web site to find the missing resistance
of R1.

To compute R1 enter Input Voltage, R2 and Output Voltage and then click Compute button.

The computation comes up with 66K.  Now subtract that same 2.5K and that is 63.5K.
Closest standard R1 resistor value is are 62K. Resistors in series will add. Don't
have a 62K, just put a 36K and 27K in series for 63K. Add as many resistances in series
that will add up to a close value. I always want to see a R1 value of at least 50K to
prevent excessive current to the input pin.  The value of R1 is less critical than
the lower value R2.  Always add at least a .1uF to ground from this pin to filter out
noise and provide a low source impedance for the A/D.  Measuring the 18V power point
of a solar panel, R1 is increased to 100K.

As tested with a 13V input and the above values, the pot voltage adjusts from 2.94
to 3.58 volts.

I believe in using what you have.  In this application a pot is used as a proportional
device. A 50K or 100K could be used just as easily by paralleling in a resistor across
the two outside contacts of the pot.  Standard resistor values of 5.1K or 5.6K would
likely work.  This is commonly used in industry since pot resistances can easily vary
20%. Using a high resistance pot with a parallel low resistance makes these dividers
more repeatable from one device another. This web site also has a calculator for paralell
resistance.  These are much faster than entering them on a calculator.


There are two pitfalls that can happen with the A/D converter. The A/D converter uses
the 5V of the on board regulator as the reference voltage. If you develop software using
the USB connector power, the numbers will change slightly when the on board regulator is
used to power the board. Even if the onboard regulator is powered, the source with the
higher voltage will dominate.  With my refrigerator those few counts changed it a couple
degrees. I ended up cutting the +5V wire on a USB cable so calibrations would not be
affected.

My camp system turns completely off at night and runs directly off panel power. The 328
micro in the UNO can run with only a few volts of power. At early dawn it will start
running with less than 3V on the 5V power supply.  This can cause all your voltage based
calculations that use A/D data to be way off.  This condition doesn't last a long time.
I use a 15 minute timer to delay any critical decisions till the sun is higher. That
delay ends long before the solar panels can put out any meaningful power. There are
other ways to accomplish this, but a time delay is simple to implement.

We often forget that this micro chip costs less than a buck. The A/D is ten bits with
some noise thrown in for free. You can count on any reading varying by about 5 counts.
Order emerges out of chaos.  Average a number of readings and that becomes a fairly
stable number.  Quite a few readings can be taken in a fraction of a second and the
world won't change much in that time.


DamonHD

  • Administrator
  • Super Hero Member Plus
  • *****
  • Posts: 4125
  • Country: gb
    • Earth Notes
Re: Getting started with UNO
« Reply #7 on: November 29, 2016, 03:32:12 PM »
As a side note it is also possible to work out what the supply voltage is completely within the chip in the UNO (no external components, I do it for my boards) and that's another way you could put off taking critical measurements until the supply is stable.  I can share the code if that helps.

Rgds

Damon
Podcast: https://www.earth.org.uk/SECTION_podcast.html

@DamonHD@mastodon.social

george65

  • Sr. Member
  • ****
  • Posts: 499
  • Country: au
Re: Getting started with UNO
« Reply #8 on: December 01, 2016, 11:18:05 AM »

Wrote out a descriptive message about the boards I bought arriving today and my dissapointment in not being able to get the LED blink function to work.
These were what I got.  http://www.ebay.com.au/itm/162279989265?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

I did finally work out I had to upload the CH 340 driver which I did and got the board to recognise in the ports.  Felt frustrated I couldn't get the damn LED to blink though. Checked out the board with a high powered magnifier and see the only LED is an ON  indicator and nothing else in place although proviso for it.

Didn't have any LED's in the box so I finally got the bright Idea of testing pin 13 with a multimeter.
Yep, can see that it is "blinking" voltage on and off and when I hold the reset button it stops till I let go then resumes. Now I'm a happy man.

I have bought a kit I'm waiting on with wires and shields etc to get me started but I have taken the most baby steps so far.
The blink I loaded was the one above so now double chuffed I got that to work.  I saved it in my library and am now getting messages about that but it does seem to be working none the less.

I have bought some Arduino compatible small relays and some SSR's today so waiting for it all to arrive as my Christmas Gift to self.
Guess the wife will be happier about me playing with these than Diesel engines in the back yard.  :0)

OperaHouse

  • Hero Member
  • *****
  • Posts: 1308
  • Country: us
Re: Getting started with UNO
« Reply #9 on: December 01, 2016, 11:56:03 AM »
I needed another guinea pig.  This is the kind of information getting started needs.  What board did you select in tools.  Try all the ones with 16mhz and 328 in the name.  I had the same problem with my NANO boards.  Think they worked with MINI PRO 328 16M. The CH340 screws up the chart as it is not an actual copy of the uno, just in board dimensions.  If that works you will be all set to use the cheap NANO.  It could be that the driver was not actually loaded so it could be accessed.
« Last Edit: December 01, 2016, 04:10:18 PM by OperaHouse »

george65

  • Sr. Member
  • ****
  • Posts: 499
  • Country: au
Re: Getting started with UNO
« Reply #10 on: December 01, 2016, 10:06:42 PM »

The board setting that is working is listed under arduino/ genuino UNO.  I tried others but that was the setting that was selected at the start. In reading the getting started pages on the arduino site, I was also thrown off by looking in the ports for something saying Arduino as they said rather than the CH340 it came up as.  I don't go poking around there a lot for the simple fact I have no need. I'm always plugging in card readers and external drives and other crap so I presumed the CH340 was something else because I was too ignorant and was looking for something that said arduino as the instructions told me it would come up. That one thing threw me off a lot and caused a LOT of wasted time and frustration.

I have ZERO knowledge or experience with these things so I was just following the numbers I was given in the hopes of getting the most basic things going. I have built dozens of computers from scratch, loaded them and set up servers as well but with this I am starting from zero knowledge save for what I have read and largely still goes 80% over my head.

Another thing that threw me was there was nothing that said 328P on the board list.  2650 or whatever it is, yes.  Also on the chip mine is marked Mega 328P so I am still not sure if that is a mega or a standard chip. From the pinouts it certainly seems to be the standard one.
When you are told to look for something and it's not there, it's easy to get thrown especially when there is nothing to say " it might also be this or that or look for something else".

It was only when looking at the board under my powerful magnifier to try and make certain of what I had been sent, I saw the chip marked CH340G and the penny dropped. I knew then I had the thing right that far. The next key was I heard the sound the computer makes when plugging in and unplugging USB devices. I had the speakers turned down at the start as my mobile phone gives interference when on my desk and it comes through so I turn them down. It was only because I was looking at things on YT to try and figure things out I turned them up and head the connection sound.

I believe the only thing I had to do was load the Ch340 drivers and it was probably working fine at that point, I just didn't realise it.  I was looking for the LED to blink not knowing enough that that board would not do that.

The thing with starting off is often the dead simple steps between 0 and 1 are not really documented well. 1-100 is in depth but the basics are presumed to work as described with no possible problems being considered.
 I find this in other things as well.  Here's how to solve this high end problem but the absolute basics weren't there. I was looking for a LED to blink. Nothing said the onboard one like in the tutorials may not exist on some boards. Nothing said if the thing compiles and says finished uploading you are good. Maybe a smarter man would have worked that out.  I do lots of things people tell me won't work and I figure out how to make it work perfectly and I would not consider myself stupid however I would say in some things I am naive, ignorant and just haven't comprehended the mentality required.
ask me about mobile phones. No, don't, never going to get my head round those things other than to make and receive a call.

It took a bit of reading to find the pin 13 thing and as this was a tutorial going back 4 years, I assumed the board I had would be like the others and the on-board LED which was shining bright would blink when the data was uploading to show I had communication AND that the most grass roots function of all with these things of the led blinking would also happen.
I didn't have an LED in my box of crap to try it, loads of Diodes, resistors, transistors and things designed for high current power but no little LED's.
I have a proclivity for Multimeters however  ( getting a bit worried I keep buying them like a fetish!) so the obvious thing to me ( finally) was to see if there was power there.

Finding it changed my mood from dissapointment and great frustration to relief and happiness. At 3am, that's a real good thing!  :0)

Now I'm trying to anticipate the shields and things I might need for the projects i'd like to do.
I'm still nervous about the coding, even learning the language to make things work but now I have got an external LED to Blink, As soon as all the wires and stuff arrive I'm sure I'll be writing sketches that will enable the Space shuttle to fly unmanned!  :0)

I have bought some Nano's already. Should arrive in a week or so.  For $1.28 ea I had to buy some just for the thrill of getting something sent to me so cheap. I think it was you that said they will do a lot of things so I thought why not?
I can't figure out how they do this.  Post a letter here is a buck! I bought 4 to make my time placing the order worthwhile!
Was also looking at buying a mega as well. Then I would have what I think is the basic set.  Mega expensive those things,  Over $10!! 
 
How many nanos in a mega power wise?  :0)

Thanks for your help and input. It is appreciated and being benefited from.

OperaHouse

  • Hero Member
  • *****
  • Posts: 1308
  • Country: us
Re: Getting started with UNO
« Reply #11 on: December 02, 2016, 10:52:04 AM »
There is a lot of cosmic angst when starting.  It's all like getting a woman to date you.  You try a lot of things and afterwords aren't sure what actually worked.

Not sure if you actually got a program uploaded from your text.  It should have said done uploading at the bottom of the screen if it did upload.  Every Arduino that I have ever seen had blink loaded into it as a verification that the board worked.  Once the board is powered up it should start blinking.  This is the reason I suggest to upload an edited blink with obviously different timing. 

Anything after the 328 refers to packaging.  At $1.28, those NANO seem too cheap.  Concerned that those do not have a USB connector and they require an additional serial board to USB to use.  These are now being dumped on the market because the USB ones have dropped in price.  I got about five of them and I can't find the serial board for a year.  I like just being able to plug directly into the board, nothing to loose.

Shields are pretty much a very bad idea unless you are only doing a single thing.  They appeal to those who are likely not to do anything with their micro.  They always end up using pins that should be used for something else.  I've only bought one that pictured socketed chips.  I planned to remove one of those chips and use the board as a general purpose driver.  It came with chips soldered in.  I never have used it.

I'm working on a two fridge program, it seems to work.

« Last Edit: December 02, 2016, 03:08:42 PM by OperaHouse »

DamonHD

  • Administrator
  • Super Hero Member Plus
  • *****
  • Posts: 4125
  • Country: gb
    • Earth Notes
Re: Getting started with UNO
« Reply #12 on: December 02, 2016, 02:16:07 PM »
Note: the P directly after 328 does imply an extra low-power mode (that I use), in addition to the P that indicates plastic packaging.

ATMEGA328-PU

vs

ATMEGA328P-PU

Or maybe I'm still confused and wrong!  B^>

Rgds

Damon
Podcast: https://www.earth.org.uk/SECTION_podcast.html

@DamonHD@mastodon.social

george65

  • Sr. Member
  • ****
  • Posts: 499
  • Country: au
Re: Getting started with UNO
« Reply #13 on: December 02, 2016, 07:12:30 PM »

This is what I bought:

http://www.ebay.com.au/itm/262685816849?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

I see now it doesn't actually say Nano so maybe I have blown 5 bucks!  going to be paying for that mistake for the rest of my days! Maybe.  :0)
It says the LED will flash so not a total loss. If these aren't nanos could you fill me in on what they are and what could be done with them?

If you know of any good Nano boards I'd be interested to see.

Your comments on the shields are enlightening.  I didn't realise that. I thought they were needed to allow the boards to perform extra functions but now understand they are simply a shortcut to manually building what you could done yourself anyhow? I envision a few single use/ dedicated setups so they may be useful for practical applications where you do want to dedicate something. They give the twits like me a better chance of success I suppose.
I have a couple of photobooths and have seen that the arduinos can be used to run them. Shields would be fine in that application as these things would be built into the box and not touched once set up and working.  Have to be better than running laptops which seem finicky at times and are a lot more exy and bulky.

Soooo many variations on these boards. Makes it very difficult for the layman to know what they need or what they should get.

OperaHouse

  • Hero Member
  • *****
  • Posts: 1308
  • Country: us
Re: Getting started with UNO
« Reply #14 on: December 03, 2016, 09:12:00 AM »
                                  A FEW RAMBLINGS

I'll be repeating some of the same things over and over again in posts.  Hopefully
it will begin to make sense after a while.

DamonHD a few posts back mentioned that there was another way to detect if the A/D
voltages could be believed.  All my controls are powered by wall warts connected to
the PV array.  The micro is stable way before these wall warts power up.  All except
a relay that connects the house battery to the fridge battery for charging.  I was
out one morning as the system was coming up and noticed this relay was on. That relay
operates with PWM for reduced current draw. At only 40ma, it wasn't much of a load. 
Still, it shouldn't have been on. When you worry about the milliamps, the amps take
care of themselves.  The solution was to add " || minutes>15 " to one statement.
ANDs " || " require statements on each side both to be true. They are the bandaids of
the software world.  When something doesn't work the way expected there is often
another condition that can be thrown in.

There are many ways to make a solution.  There are no software police.  Whatever you
write will be hidden away.  What is important is you can understand it. If you want
to make five analogRead in a row and then add them all together to form an average,
that is fine. The same code can be repeated over and over instead of doing a loop.
You will not run too slow or run out of memory with anything you are likely to program.
I stay away from attaching variables to pins and limits in the sample code I show.
I think it initially over complicates things in the beginning. Just way too much
printing on a page. Some may notice I use " count >= 25 " when " count == 25 " could
have been used.  I do that because sometimes a code error can jump the shark. If that
25 is passed it will just go on forever.

I put blinktime in all my programs.  It is a good visual indicator of what is happening.
Too fast or too slow indicates something is not working the way you expected. Sometimes
it doesn't blink at all. It is one way to see inside that chunk of plastic. Blink is also
a convenient debug tool. Adding a line " digitalWrite(13,1); " and maybe a delay can
indicate that point in the program was reached. Inevitibly you will get stuck and it is
good to have the friend blink.

The first thing to put in a program is a debug screen. Data can be accessed by going
into TOOLS and clicking on SERIAL MONITOR.  This is also where blinktime can be handy.
Printing out data every loop may be necessary initially, but it adds time to the program
and the data just races down the screen.  At the bottom left hand section of the screen
ia a little box marked SCROLL.  That can be turned off and you can manually look back at
each transmission of data. Adding blinktime to the print routine will allow speeds of
once per second or longer. Just remember that the last serial print has to be a println.
Otherwise it will write on one line forever.

What new programmers will have the hardest problem with is thinking in a mathematical
way. The best programmers will fail if they can't make a mathematical model of what
they want to accomplish.  I have a Morningstar controller in my garage that turns on
an outside lamp.  The lamp is on for two hours after sunset and two hours before sunrise.
Seems like a lot of magic.  How does the controller know that?  You can look at the
solar panel voltage and when it drops to a minimal value, that is sunset.  Then the
light is turned on for two hours.  How does it know when sunrise is?  It doesn't the
first day. It counts the minutes from sunset to sunrise and saves that number.  The
next day it starts counting minutes after sunset and when it trackes that count minus
two hours the lamp turns on again.  By storing a new count each day it tracks through
the seasons.

A blinktime of 200 is a convenient number.  In my fridge program that takes about 10
seconds before it resets.  That gives an identifiable start and end to the flashes.
Counting a few blinks is easy and long or short blinks are obvious.


                     WARNING  WARNING  WARNING

I need to say that I have an aversion to what I call BIG DATA. The 328 is a little
snot of a micro for simple dedicated stand alone operation.  There are people who
want to add data storage, GPS, WIFI, massive displays, etc. Your home refrigerator
doesn't have a gigantic control panel indicating all the power used in a day with
charting. You set it and forget it. I am willing to help people with the fundimentals.
Not interested in anything beyond a blinking LED. That is all my house has. I encourage
people to investigate these devices.  There are plenty of tutorials on the internet.
Just a warning not to expect I will finish your project if you just buy the parts.

On another board someone was asking for help.  I made a couple suggestions, but the
thread kept getting longer, the OP seemed clueless.  I asked a question I had pondered
for a long time. With all these answers, how did they decide who to listen too. He responded
that he would let everyone fight it out and use the design that remained.  It's a plan.
Just not one I wanted a part of.
« Last Edit: December 03, 2016, 10:26:42 AM by OperaHouse »

Bruce S

  • Administrator
  • Super Hero Member Plus
  • *****
  • Posts: 5370
  • Country: us
  • USA
Re: Getting started with UNO
« Reply #15 on: December 03, 2016, 04:16:16 PM »
Operahouse;
I don't want you to go getting all teary eyed, blushing or aww-shucks on me.  :P
BUT I have to say this:
This is the very type of professors (mentors) I always went looking for and in the world of GIS training I'm still looking for. I don't really need someone holding my hand or doing it for me, there's NO learning that way. Just a gentle nudge is okay .

Don't tell me the answer , give me the steps, in a nice logical way. I'll get to the finished end,,, eventually.
I've had to back off my learning to program these little buggers, work,, ya know, but I do try to keep up. AND have yet to post any of my sketches, mainly due to them being mere clones of what other people have done, with simple time changes to meet my needs, and NO where near as complete or eloquent as your solutions.

It is nice to know simple math will get me where I need to go with these.
NOW if DamonHD will just post his code so I can "borrow" from it I'll be all set.  :o


Thanks
Bruce S
A kind word often goes unsaid BUT never goes unheard

OperaHouse

  • Hero Member
  • *****
  • Posts: 1308
  • Country: us
Re: Getting started with UNO
« Reply #16 on: December 03, 2016, 07:06:18 PM »
another way you could put off taking critical measurements until the supply is stable.  I can share the code if that helps.

Damon

Many hands make light work. People don't need permission to add to the discussion. It is a bunch of work editing and trying to think how someone else will interpret the words.  I got sucked into being the ISO Quality Auditor at prior employment and had to rewrite 80% of test procedures.  With ISO you are supposed to be able to take anyone off the street and turn them into a test tech.  In one test procedure I wrote to take a 12V power supply and connect the positive red lead to pin X.  They hooked up an AC power supply and it didn't work.   My BAD.  As Deming says...All problems are the result of management.  I was in Home Depot and a sales staff was trying to explain how to wire a new branch into a panel.  Their eyes were glazed over.  And then ontfarmer quotes from one of my posts.  Boy do I need a proof reader.  We will just have to see if some programmers can be created.  Some of these little programs can make a big difference in system performance.