Show Posts
Pages: [1] 2 3 ... 53
1  Using Arduino / Programming Questions / Re: Alternative IDE on: July 10, 2014, 01:19:28 am

Atmel's AVR Studio is one option......

There is any version for Linux? No, right (or at least I don't see it)?

I have written a lot of very large and complex programs for the Arduino and have never needed a full blown IDE with projects, version control and all the other blah-blah that AVR Studio and most other "development studios" provide.

A good text editor, gcc-avr and avrdude is all anyone really needs.

BTW, I also use Linux (kubuntu 14.04).
2  Using Arduino / Programming Questions / Re: Alternative IDE on: July 10, 2014, 01:15:53 am
I was looking to know if there is any alternative IDE for arduino.

If you run Windows, you would probably be happy with a good text editor such as EditPad Pro

( http://www.editpadpro.com ).

It has syntax highlighting, brace matching, line numbers, search and replace, full regex support, etc... everything you need to manage your source.

Then, use the Arduino IDE in "external editor" mode solely to compile and upload the code.

I run Linux and use Kate (KDE text editor) to write Arduino code, then use the Arduino IDE just to compile and upload.

(btw, I am not affiliated with EditPad or JGSoft... I just have experience with their editor and highly recommend it).

3  Using Arduino / Programming Questions / Re: Still a bit stuck with { }, return and exit. on: July 10, 2014, 01:07:25 am

Is it simply to "close" off the { }'s?


A "subroutine" (function) optionally takes and optionally returns data.

For example, a function to add two integer numbers:

Code:
int add_two (int a, int b)
{
    int answer = (a + b);
    return answer;
}

The "int" before the name "add_two" means the function will return an integer number. The ints in the parentheses define the variables "a" and "b" as integer numbers.

Inside the function, a variable named "answer" is declared and at the same time set to the value of "a + b".

Lastly, it's returned to the caller.

Now, a function that returns a number, but takes in nothing (useless, but it will help you understand the differences):

Code:
int useless (void)
{
    int a = 3;
    int b = 5;
    int c = (a + b);
    return c;
}


All this does is return the number "8" in the form of an "int" which is a signed 16 bit number (meaning it can range from -32768 to +32767).

Notice that since it takes in nothing, the parameter is called "void". But, it returns an int, so "int" precedes the function name.

Now, put it all together (with a little pseudo code for simplification):

Code:
int main (int argc, char *argv[])
{
    print "Enter the first number: " // not real C code
    int a = get_input (); // hypothetical function that gets user input
    print "Enter the second number: "  // not real C code
    int b = get_input (); // hypothetical function that gets user input
    int answer = add_two (a, b); // call add_two, place return value in "answer"
    print "The sum of the two numbers is answer" // "answer" actually prints the variable value, not the word "answer"
}

Hope this makes sense....
4  Using Arduino / Programming Questions / Re: Printing long number to LCD with separators. on: July 07, 2014, 07:11:50 am

@Krupski: Even with that 787 posts, I think you need to take a look to the rules of the forum, specially the part of posting code:
http://forum.arduino.cc/index.php?topic=97455.0



I know full well to use the CODE tags.

I posted it the way I did because the CODE tags do not allow the bold or color BBcodes to be used, and I wanted to highlight certain lines.

The point of using the code tags is to make posted code readable. Is not the way I did it AS READABLE as the code tags?
5  Using Arduino / Programming Questions / Re: Printing long number to LCD with separators. on: July 07, 2014, 07:09:45 am
Quote
Yes. You are missing two things:

(1) How to actually be helpful
(2) How to be polite
If (1) means failing to provide the code, I get PAID for that. I prefer to teach people to think for free.

As for (2), point out just EXACTLY where I am being less than polite.

I get paid to teach college students electronics. I don't expect to get paid here. Here, I do it as a hobby, for fun.

As far as "failing to provide code", I don't necessarily think that giving someone pre-written code is the right course of action. It all depends on the circumstances. But, simply answering a question with another question is rarely helpful.

Concerning this particular thread, the way I would have done it is to say something like "Do you see where you put your comma and dot? The comma is at the one thousands place and the dot is at the one one-thousandths place. Therefore, if you divide the number by 1000 and count how many times you had to do that in order to reduce the number to one, that will tell you how many commas you need, and of course they go every three digits".

The way you did it is technically correct, but provides little insight into WHY it's done. Someone who is asking a question (even a ridiculously simple one) is not seeing the obvious in front of their face. We've all done that, and a little hand holding at a point like that is VERY helpful.

Of course, this is all just my personal opinion, which is worth all of 2 cents......  smiley
6  Using Arduino / Programming Questions / Re: Printing long number to LCD with separators. on: July 07, 2014, 07:02:49 am
Output is fequency in Hz for frequency from 1MHz to 6GHz.
If freq > 10MHz then output is "XX,XXX.XXX Hz"
If freq > 100MHz then output is "XXX,XXX.XXX Hz"
If freq > 1000MHz then output is "XXXX,XXX.XXX Hz"
else
output is "X,XXX.XXX" for freq < 10Mhz

The following code is a small utility I wrote to display CPU speed in Linux. But the parts highlighted in blue show how to scale the number and display a suffix such as "Hz" or "MHz" or "GHz"... this may be of some help to you.


/***********************************
 * cpus.c wednesday 30 april 2014
 ***********************************/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <inttypes.h>
#include <unistd.h>

const char *govinfo = "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor";
const char *cpuinfo = "/proc/cpuinfo";
const char *target = "cpu MHz\t\t: ";
const char *hertz[] = { "", "k", "M", "G", "T", "P", "E" };

FILE *fp = NULL;

char *buf = NULL;
char *ptr = NULL;

uint8_t allflag = 0;
uint8_t freqflag = 0;
uint8_t govflag = 0;
uint8_t hzflag = 0;

uint32_t x = 0;
uint32_t y = 0;
uint32_t multiplier = 0;
uint32_t cores = 0;
uint32_t targlen = 0;
uint32_t fsize = 0;
uint32_t precision = 0;

double *freq = NULL;
double *re_alloc = NULL;
double avg = 0;

const char *strip_path (const char *str) {
   uint32_t ofs;
   ofs = strlen (str);

   while (ofs--) {
      if (* (str + ofs) == '/' || * (str + ofs) == '\\') {
         break;
      }
   }

   ofs++;
   return (str + ofs);
}

int main (int argc, char *argv[]) {
   opterr = 0; /* suppress getopt's built in error messages */
   precision = 3; /* default precision */

   while ((x = getopt (argc, argv, "afghp:")) + 1) {
      switch (x) {
         case 'a' : {
               allflag = 1;
               break;
            }

         case 'f' : {
               freqflag = 1;
               break;
            }

         case 'g' : {
               govflag = 1;
               break;
            }

         case 'h' : {
               hzflag = 1;
               break;
            }

         case 'p' : {
               precision = atoi (optarg);

               if ((precision > 9)) {  /* sanity check */
                  precision = 3;
               }

               break;
            }

         case '?' : {
               if (optopt == 'p') {
                  fprintf (stderr, "%s: option -%c requires an argument\n\n", strip_path (argv[0]), optopt);
                  return 1;

               } else { /* print out simple help */
                  fprintf (stdout,
                         "\n"
                         "Usage: %s [options]\n"
                         "  -a  display all cores separately\n"
                         "  -f  display frequency only\n"
                         "  -g  display governor in use\n"
                         "  -h  display in hertz (don't scale)\n"
                         "  -p<n>  display precision n (default:3)\n"
                         "\n",
                         strip_path (argv[0])
                        );
                  return 1;
               }
            }

         default : {
               fprintf (stderr, "\n%s: switch/case/default: should never see me\n", strip_path (argv[0]));
               return 1;
            }
      }
   }

   fp = fopen (cpuinfo, "rb");

   if (fp == NULL) {
      fprintf (stderr, "%s: open %s for read failed\n", strip_path (argv[0]), cpuinfo);
      return 1;
   }

   while (!feof (fp)) { /* fseek/ftell doesn't work on /proc files */
      fgetc (fp);
      fsize++;
   }

   fclose (fp); fp = NULL;
   ptr = buf = (char *) malloc ((fsize + 1) * sizeof (char));

   if (!buf) {
      fprintf (stderr, "%s: malloc failed (buffer)\n", strip_path (argv[0]));
      return 1;
   }

   freq = (double *) malloc (1 * sizeof (double));

   if (!freq) {
      fprintf (stderr, "%s: malloc failed (freq)\n", strip_path (argv[0]));
      return 1;
   }

   fp = fopen (cpuinfo, "rb");

   if (fp == NULL) {
      fprintf (stderr, "%s: open %s for read failed\n", strip_path (argv[0]), cpuinfo);
      free (buf); buf = NULL;
      free (freq); freq = NULL;
      return 1;
   }

   fread (buf, sizeof (char), fsize, fp);
   fclose (fp); fp = NULL;
   targlen = strlen (target) - 1;

   for (x = 0; x < fsize; x++) {
      if ((* (buf + x) | 0x20) == (* (target + y) | 0x20)) {  /* ignore case */
         if (y == targlen) {
            ptr = buf;
            ptr += x;
            * (ptr + targlen) = 0;
            * (freq + cores) = atof (ptr) * 1.0e6f; /* MHz. -> Hz. */
            multiplier = 0;

            if (hzflag) {
               precision = 0;

            } else {
               while (* (freq + cores) > 1000.0) {
                  * (freq + cores) /= 1000.0;
                  multiplier++;

               }
            }

            avg += * (freq + cores++);
            /* allocate storage for next core freq */
            re_alloc = (double *) realloc (freq, (cores + 1) * sizeof (double));
            freq = re_alloc;

            if (!freq) {
               fprintf (stderr, "%s: realloc failed (freq)\n", strip_path (argv[0]));
               free (buf); buf = NULL;
               /*   free (freq); freq = NULL; */
               return 1;
            }

         } else {
            y++; /* find next char of match */
         }

      } else {
         y = 0; /* reset find pointer */
      }
   }

   for (x = 0; x < cores; x++) {
      if (govflag) {
         sprintf (buf, govinfo, x);
         fp = fopen (buf, "rb");

         if (fp == NULL) {
            fprintf (stderr, "%s: open %s for read failed\n", strip_path (argv[0]), buf);
            free (buf); buf = NULL;
            free (freq); freq = NULL;
            return 1;
         }

         fgets (buf, fsize, fp);
         fclose (fp); fp = NULL;
         * (buf + (strlen (buf) - 1)) = 0;
      }

      if (!freqflag) {
         fprintf (stdout, "%s", allflag ? "Core" : "Average of");
         fprintf (stdout, " %d", allflag ? x : cores);
         fprintf (stdout, "%s", allflag ? ": " : " cores: ");
      }

      fprintf (stdout, "%.*f", precision, allflag ? * (freq + x) : avg / cores);

      if (!freqflag) {
         fprintf (stdout, " %sHz.", * (hertz + multiplier));
      }

      if (govflag) {
         fprintf (stdout, " [%s]", buf);
      }

      fprintf (stdout, "\n");

      if (!allflag) {
         break;
      }
   }

   free (buf); buf = NULL;
   free (freq); freq = NULL;
   return 0;
}


Note: Stuff like this:

*(buffer + offset)

is the same thing as:

buffer[offset]


Hope it helps...

-- Roger
7  Using Arduino / Programming Questions / Re: Printing long number to LCD with separators. on: July 07, 2014, 06:51:06 am
Am I missing something?

Yes. You are missing two things:

(1) How to actually be helpful
(2) How to be polite
8  Using Arduino / Programming Questions / Re: SPI 32 bit on: July 02, 2014, 06:09:24 pm

Could anyone possibly explain the bitwise operator parts of the code for me in detail, I would VERY much appreciate it since I have tried understanding it but it is proving very difficult.  I am using an arduino uno though, so I'm not sure if it can store 32 bits and it might have to be split up into a set of 16 bits?

You don't need to split anything up.

The Arduino SPI hardware transfers 8 bits at a time, so to transfer 32 bits, you need 4 SPI calls.

Imagine this: You have 4 dinner plates. Each plate is an 8 bit byte.

You receive the first byte, put it on the first plate, then place the plate on the table.

You receive the second byte, place it on the second plate, then lift up the first plate and slide the second one under it.

You receive the third byte, place it on the third plate, then lift up the first two plate and slide #3 underneath.

For the fourth and final byte, you do the same thing.

Now you have a vertical stack of 4 plates, The top plate, having been lifted up (shifted) three times now occupies the most significant byte of the 32 bit long word. The bottom plate is the least significant byte.

Let's look at it another way. Imagine I want to send you the hex number 0x12345678, 8 bits (one byte) at a time.

You start out with an "empty" uint32_t (32 bit long word).

I send you the first byte which is 0x12. You place it into your variable. It's current value is 0x00000012

I then send the next byte (0x34) to you. You shift your variable to the left 8 bits which results in your variable now being 0x00001200

Then you add in the second byte which results in you having 0x00001234

Now I send you the third byte (0x56). You again shift your variable to the left 8 bits resulting in 0x00123400. Then add in byte #3 which results in you having 0x00123456

I send the last byte (0x78). Again you left shift 8 bits which results in 0x12345600. Then add in your last byte and you have 0x12345678

Hope this makes sense.
9  Using Arduino / Programming Questions / Re: Using a font on: July 02, 2014, 05:47:18 pm
Hello,

I'm discovering the display of caracters on 128x64 OLED. I compiled a program using 24x40 font , now I have to replace py 16x16 font
I put BigFont.c  in the right folder -till here this is ok smiley-wink
displaying a caracter is made calling this function
Code:
void drawCar(int sx, int sy, int num, uint8_t *font, int fw, int fh, int color) {
  byte row;
  for(int y=0; y<fh; y++) {
    for(int x=0; x<(fw/8); x++) {
      row = pgm_read_byte_near(font+x+y*(fw/8)+(fw/8)*fh*num);
      //macro that reads a byte of data stored in a specified address(PROGMEM area)
      
      for(int i=0;i<8;i++) {
        if (bitRead(row, 7-i) == 1) display.drawPixel(sx+(x*8)+i, sy+y, color);
      }
    }
  }
}

but it is not displaying the numbers it used to do with the previous font .. what should I modify . I actually don't understand well how this works at the level of font.c content and calculation font+x+y*(fw/8)+(fw/8)*fh*num



 

If your display is KS108 compatible, the data is displayed as follows (assuming an 8x8 pixel letter "P"):


Byte    0   1   2   3   4   5   6   7
-------------------------------------
Bit     0   0   0   0   0   0   0   0
        1   1   1   1   1   1   1   1
        2   2   2   2   2   2   2   2
        3   3   3   3   3   3   3   3
        4   4   4   4   4   4   4   4
        5   5   5   5   5   5   5   5
        6   6   6   6   6   6   6   6
        7   7   7   7   7   7   7   7

        . # # # # . . .
        . # . . . # . .
        . # . . . # . .
        . # # # # . . .
        . # . . . . . .
        . # . . . . . .
        . # . . . . . .
        . # . . . . . .


        0x00,0xFF,0x09,0x09,0x09,0x06,0x00,0x00



Knowing how the bits are laid out will help you understand the seemingly odd addressing that goes on to locate fonts. Also, you will see that if you digitize an existing font which runs left to right, it will display rotated by 90 degrees on the display.

Note that all screen fonts SHOULD be multiples of 8 pixels in size. For example, 8x8 or 8x16 or 16x24 or 16x32... this makes crossing "chip" boundaries (the left and right half of the display) easier.

By the way, take a look here: https://github.com/krupski/Noritake_VFD_GUU100

Check out the "fonts" subdirectory. There are a bunch of various sized bitmap fonts for a 128x64 display. Maybe they will be of some use to you. It's free GPL3 software, so help yourself.

Hope this helps.
10  Using Arduino / Project Guidance / Re: Reducing DC voltage for a project on: July 02, 2014, 12:15:54 am
Quote
What's a ubec?

UBEC = Universal Battery Eliminator Circuit.

It's a module used to drop "high" voltage (20 to 30) down to 6 volts for radio control servos and radios.

It's completely useless for the OP's requirements, which makes me wonder why "Voltage Divider Johnny" even mentioned it (or for that matter why he mentioned resistors).
11  Using Arduino / Project Guidance / Re: Reducing DC voltage for a project on: July 02, 2014, 12:11:50 am
I have a computer connected to my Arduino on a robot platform.  The Arduino will get 5 volts from a USB connection, but the computer takes 19 vdc at 40 watts.  I only have two 12-volt car batteries, for a total of 24 volts.  The batteries are already connected in series, so I can't step up the voltage from one battery, I can only reduce the voltage from the pair.

Does anyone have an easy way to reduce this voltage from 24 volts to 19 volts at 40 watts?

24 volts to 19 volts at 40 watts means you have to drop 5 volts at about 2.1 amperes. Using a simple linear regulator, you would have to dissipate about 10 watts of heat. Not at all too bad.

I would use an LM350 and program it with a 150 ohm / 2200 ohm set.

Put it on a decent heatsink and you're all set.
12  Using Arduino / Project Guidance / Re: Reducing DC voltage for a project on: July 02, 2014, 12:05:04 am
19 V is a fairly standard laptop supply voltage, isn't it?

Yes it is. My Acer monitor also has a 19v switching power supply.
13  Using Arduino / Programming Questions / Re: T1 timer counter sketch on: June 30, 2014, 01:11:08 am
I am trying to figure out why D8 is the input pin in the attached sketch from Nick Gammon.
However I am at a loss.
How is D8 defined in the code?

Wow... I think you're going to have to ask Nick about that. If you assume that D8 means "digital pin 8", that doesn't work because pin 8 on either UNO or MEGA2560 isn't involved with the timer and input capture.

Then I wondered if "d8" is a hex value... but that doesn't work either.

I'm at a loss here......
14  Using Arduino / General Electronics / Re: Component, can anyone identify this? on: June 24, 2014, 09:34:53 am
I have attached a few pictures of an electronics component, very old, was used on a board to power a DC motor.
The component burned up and I need to know what it is in order to replace it.

So if anyone could identify the component, that would be great.

Thanks!

That's the same kind of package that the rectifier diodes of an old Mopar (Chrysler) alternator used. But, since the parts you pictured have three leads (two top, plus the body), I will guess that it's an SCR.

Is there any kind of number on it?
15  Using Arduino / General Electronics / Re: Need help learning to calculate a base resistor for a transistor on: June 24, 2014, 09:25:29 am

Huh?

When you're PWMing high power LEDs (or motors or whatever) with logic level MOSFETs and a 20mA I/O pin you most definitely have to worry about the values listed in the datasheet under "capacitance".

Real engineers have even designed special "mosfet driver ics" to help.


Worrying about I/O pin limitations of an AVR chip and reason for "motor driver chips" is two completely different things.

Lots of people here seem to think that the MOMENTARY high current spike which results from driving the gate of a MOSFET with an Arduino port requires a current limiting resistor. Indeed it does not.

The MOSFETS in the output pin drivers of the AVR have inherent ON resistance. An over current condition simply causes heat to be generated in the MOSFET. The VERY short time that the over current condition lasts due to charging or discharging a few picofarads of gate capacitance will not damage the device in any way. Any heat generated during that brief period is probably too small to even measure.

In fact, DURING the switching from logic high to logic low (or vice-versa), there is a brief period where both the top and bottom "totem pole" driver MOSFETS are conducting at the same time, causing a very brief short circuit across the power supply and a large current spike. This is why devices like the AVR need small but very low ESR and high frequency bypass capacitors across VCC and GND. Obviously, the brief short circuit condition does not hurt the device.

With motor drivers (or any other high power MOSFET controller), it is important to drive the gates with a low impedance source in order to minimize the switching time and therefore minimize the time that the MOSFET is in a partially conducting state. That's why high power MOSFET drivers are used.

With this in mind, using a series resistor between an Arduino and a MOSFET gate is the worst thing to do because it slows down the switching time, leaving the MOSFET in the partially conducting region longer and increasing power dissipation and heat.

It's BETTER to drive the MOSFET gate "hard" by directly connecting it to the AVR digital pin without a resistor.

Concerning the "sarcasm" part of my post, I'm sure you've seen the same few people instantly answer every post (presumably to run up their post counts) and then only write snotty things to the OP. Here are a few that I will look for right now and quote for you:

Quote
You don't check that there IS anything to read before reading. Stupid.

Quote
Dumb! Local variables with the same name as global variables are virtually never a good idea.

Quote
a) Thanks for wasting everybody's time with the TIP120

Quote
Try and talk to people who know what they are talking about.

I could go on and on, but I think you get my point. It makes me wonder, why should *I* go through the bother of trying to properly and politely explain something that the OP clearly doesn't understand and clearly wants to LEARN when terse, cryptic "answers" and sarcasm seem to be acceptable to the moderators?

Even when an answer IS half-helpful, it really isn't. I've seen so many times things like "1K is wrong, use a 220".

Well, fine, but WHY? What's the reason? How is it calculated? What happens if 1K is used? Why?

I've been involved with electronics for over 35 years. I very rarely post a question here, simply because I don't need to. I post here because I find it fun and relaxing to try to help and teach people, in the hope that they will end up loving electronics and having as much fun as I do.

And it REALLY ticks me off to see wannabe "engineers" spout off incorrect information, teach nothing and reply with sarcasm. Why bother? Is it FUN to hurt other people? I don't think it is.
Pages: [1] 2 3 ... 53