Which Library Development Environment?

I'm finding library development slow going. I want to develop my own libraries for Arduino without the constant code-compile-load-run routine. I've tried Processing (doesn't use .h and .cpp files like Arduino) and I've looked into using Eclipse for C/C++ development (too much set-up and screwing around).

What do people use to write libraries? Or does nobody write their own libraries from scratch?

Thanks!

I want to develop my own libraries for Arduino without the constant code-compile-load-run routine

How else are you going to debug and test?

An emulator/simulator?
If you're interacting with hardware or built-in peripherals, these can be even more of PITA to get working than the cycle you describe.

I use Notepad++ and logic. If you design your program first, on paper or using some tool on the computer, you might cut the cycle drastically.
A lot of my libraries are written cycling just once: Arduino Playground - AlphaBeta

You should try to become your own compiler, and embed a lot of mental cues in your code.
If you once have a bug because you do if (x = 42) and meant if (x == 42)then adopt a convention to always start with the constant like if (42 = x) which will be an error, and it looks like an error as well, right? Then you spot that, and correct it to if ( 42 == x) without the need for a complete cycle.
Always comment code that are not self descriptive and that use many language constructs (no need to comment that a getChar method gets a char, and it is no need to comment that i++ increments i).

I also find that it's a good exercise to manually run through the code, as a personal core review and a verification that the logic is sound.

Good luck! Writing libraries for the Arduino has thought me a lot, I'm sure it will teach you a lot as well.
Any problems? Just ask :slight_smile:

I use Notepad++

I second that,

When writing a library I always start with thinking about the interface. What functions make sense? What param-list makes sense per function? What internal structure is needed? - and yes in this last step I often use paper - Then I start coding with the constructor and build up the lib in small steps, and testing (almost) every step.

For parts that are just logic, I write them on a real computer and create test harnesses and test them in a UNIX environment with a debugger, if necessary. When they are working as expected, I paste them into a sketch or module.

This is only possible for something like a communication protocol or something, that has very fixed interfaces. If you have interrupts or special hardware to debug, you have to do it on Arduino hardware.

I have found some things help there: Using a MEGA gives you extra HW UARTS, which may make it easier to generate debugging information. It also has more memory, so having gobs of extra debugging crap around -- buffers to format debug messages and strings and whatnot is much more feasible.

I wrote a Makefile as a build/test harness for my LCD library, and work on everything using my traditional tools (vi, make, gcc, etc) on my native machine (I actually went so far as to write a thin ncurses-based "LCD" backend for testing my drawing routines, which also forced me to abstract the hardware out a bit more).

So basically, for things that aren't explicitly tied to hardware, it's make, gcc, and vim for me. Your tools may vary. :slight_smile:

I write them on a real computer and create test harnesses and test them in a UNIX environment with a debugger, if necessary. When they are working as expected, I paste them into a sketch or module.

+1
With EMACS, of course :slight_smile:

Ohnohedidnt. :slight_smile:

Thanks everyone, I value your experience and efforts to help me. Gardner got closest to what I was looking for. I should have said I'm writing "just logic" classes like Time; Text (String); Location (for GPS). I can remove dependency on actual hardware by, for example, mocking a GPS device that just returns a single NMEA sentence when called. I guess I want a "nice" C/C++ environment for Win7. I have run Ubuntu in the past (and loved it) but had hardware issues with my current machine. I've developed in Notepad++ with cygwin and had good success, but it's not integrated. I guess I could try Visual Studio? Oh hey, here's a question.

If I write and run C++ on a Windows machine, aren't all the data types 32-bit, or even 64-bit? If I want to test for things like overflow on an 8-bit integer I'd have to somehow define an 8-bit data type wouldn't I? Otherwise it's not actually simulating what would happen on an 8-bit microcontroller, is it?

Being a Computer Science student and professional developer (shock!) I'm not much interested in plugging in hardware and mashing together bits of other people's code. I want to write it all from scratch! That means countless hours developing libraries (as I've already done) that perform functions like the built-in String and available NewSoftSerial classes already do. It's as much about learning to write (fast and light) code for microcontrollers in general as it is to complete one of the many project ideas I have.

This forum is an amazing resource. Thanks again. No doubt I'll have another question shortly ...

Prawnhead:
Being a Computer Science student and professional developer (shock!) I'm not much interested in plugging in hardware and mashing together bits of other people's code. I want to write it all from scratch!

This probably what most of us CS geeks thinks (especially while we're students), but it will get you nowhere in the real life. Actually, it will get you somewhere, and that is last.
UNLESS you're lucky enough to discover something no one has ever done before.

The sooner you learn the skill to 'mashing together bits of other people's code' the sooner you will become a great developer.
:slight_smile:

aren't all the data types 32-bit, or even 64-bit? If I want to test for things like overflow on an 8-bit integer

I got caught porting a program to a Burroughs (I think) main frame years ago. A lot of the code used hash tables for lookup and calculating the hash values required catching overflow from 8-bit values.

The main frame had 9-BIT BYTES. Man that took some time to figure out :slight_smile:


Rob

If I write and run C++ on a Windows machine, aren't all the data types 32-bit, or even 64-bit? If I want to test for things like overflow on an 8-bit integer I'd have to somehow define an 8-bit data type wouldn't I? Otherwise it's not actually simulating what would happen on an 8-bit microcontroller, is it?

No; there would be revolution in the street. There are now standard defined types for data of a particular size (int8_t, int16_t, int32_t, int64_t and similar uint types for unsigned), and portable code should use those. "char" is almost always 8bits, "short" is almost always 16bits. Things beyond that get complicated. (for portable code be especially careful not to assume that sizeof(void*) == sizeof(int) !)

I generally find "Integrated" to be overrated. A good set of more customizable tools ends up being more powerful. That said, "Eclipse" and "Netbeans" seem to be the up-and-coming standard IDEs, and include a good deal of customization capabilities.

I use Netbeans and love it. The Arduino port is not 100% I think and I have some issues with creating a new project but overall it's great.

However I just use it as a fancy editor, and make launcher. I still have a normal make file.

BTW, I just downloaded Notepad++, thanks for the tip there fellas, that's a keeper, it will be replacing my other programming editor (Textpad) I've been using for a long time.


Rob

Hey AlphaBeta, I have a pathalogical drive towards "perfection"; don't most programmers?. No mistakes. Correct code. My work day is 100% compromise and drives me crazy, so my Arduino stuff is my own little bit of nirvana. I know it's a fool's quest, but I have fun learning everything I can! Maybe I should switch to assembler so I can have bare-metal control? Hmmm - there's an idea.

Thanks for the reality check though!

From my experience, most Computer Science students do not care about writing code from scratch. Most I know seem/seemed happy to use something premade.
I couldn't stand using someone else's code :stuck_out_tongue:

That said, I use Code::Blocks. Not many people seem to talk about it, but me + Code::Blocks = happy. Oh yeah, +gcc also of course, but that can go without saying.

About your all datatypes being 32-/64-bit question...
Yes and no. For Windows. (And most Unix OS's)

You can store 8-bit values all you want on Windows, and have them act as such. The thing you must be aware of is word size.
In a 32-bit edition of Windows, 2^32 words are accesible. Each word is treated as 4 bytes, or 32 bits long. Because there are 2^32 separate addresses, and they have a 32-bit "resolution" due to 32-bit words (that is, if the numerical difference between two pointer values is 1, then they are 32 bits apart), the system must strip a whole word from memory, then just grab the first byte.
Likewise with 64-bit... but with 64-bits. Which is one of the reasons I am against 64-bit. Stripping whole words for 32-bit values is just ridiculous. There's always the argument amount a boolean value taking a whole word too in this sense!

Anyways. Code::Blocks. Check it out :slight_smile: It's a slight pain for quick work unless you know/set-up some shortcuts. It allows you to work on single files of course, but like Eclipse/Netbeans, it is focused on a "Project" view.

Or use some Notepad-like program. Nothing wrong with Notepad++.

if the numerical difference between two pointer values is 1, then they are 32 bits apart

No. Various x86 CPUs have a data path to memory that is more than one byte wide, but it's still a byte-addressable machine... (However, note that in C, the difference between two pointers is always in units of the pointed-to object.) Try it:

#include <stdio.h>
#include <stdint.h>

char bytearray[10];
short shortarray[10];
long  longarray[10];
struct {
    int a,b,c, d;
} structarray[10];

main()
{
    uintptr_t first, next;

    first = &bytearray[0];
    next = &bytearray[1];
    printf("byte diffs ptr: %d, uintptr %d\n",
	   &bytearray[1] - &bytearray[0],
	   next - first);

    first = &shortarray[0];
    next = &shortarray[1];
    printf("short diffs ptr: %d, uintptr %d\n",
	   &shortarray[1] - &shortarray[0],
	   next - first);


    first = &longarray[0];
    next = &longarray[1];
    printf("long diffs ptr: %d, uintptr %d\n",
	   &longarray[1] - &longarray[0],
	   next - first);


    first = &structarray[0];
    next = &structarray[1];
    printf("struct diffs ptr: %d, uintptr %d\n",
	   &structarray[1] - &structarray[0],
	   next - first);

}

Thanks Camalaio ... downloading Code::Blocks ... and I appreciate your other input too!

westfw:
No. Various x86 CPUs have a data path to memory that is more than one byte wide, but it's still a byte-addressable machine... (However, note that in C, the difference between two pointers is always in units of the pointed-to object.)

Doh. That was rather silly of me to just throw out there.
There are certainly accomodations for <32-bit datatypes. Not to mention that I usually get annoyed at certain pointer types and size_t. size_t is lovely and horrid at the same time for me.

I know you can still address by byte. More accurately I should have said that it has a resolution of 1 byte, or 8 bits. That does not change between 32/64 bit architectures, as far as I know. What I meant is that the system still needs to strip a whole word, but still knows where the byte is within the word and within all addressable memory.

Which, according to all sources that I know of, is accurate. I'll tear through some journals and articles at some point if someone thinks/knows I'm wrong and I have time.

Sorry for the confusion!

I use Qt Creator. Powerful, easy to use and all that. Only problem is you need to save in Qt, re-open the Arduino IDE and then first you can compile a sketch.

JanD