Arduino Novice; Writing Hardware Drivers & Sample Code; Initial Guidance Needed

I am in the middle of a project that combines hardware design and software to operate that hardware. Please do not ask for all the specifics as it is proprietary. I will provide as much as I believe is needed and as I can. The hardware has been designed and tested with another PIC device (PICAXE 08M2). No hardware problems were apparent, so that part of the design is fairly fixed at this point. One of the goals of this project is for the hardware to be as universal as possible as regards the micro controllers/PICs that it can operate with. Hence, I am now tasked with the job of writing driver and demonstration software for additional devices and the Arduino is next on my list. I have an Arduino Uno to play with but the code I come up with should be usable with as much of the Arduino line as possible, with the least amount of modification.

In addition to being a complete novice with the Arduino, I am also a beginner with C++ code. I am currently on about page 85 of a Dummies book on it. Probably going to take me another week or so. Also looking up things on the internet and asking a question or two on a C++ BB. Hopefully I will be able to avoid some stupid questions on basic C++ symtax, etc. But I would like to ask some general questions so that I can better determine the rough course I need to follow in doing this. This will help me to focus on the parts of the C++ language that are more important in this task. And also to choose a good general approach.

The code will probably be divided into two parts: first the necessary routines to actually communicate with the hardware and second a main routine that will demonstrate it's various capabilities. Communication is one way only, from the microprocessor (Arduino) to the hardware. The communication routines will need to send groups of 14 bits from one pin of the Arduino with 14 clock pulses on a second pin when the data bit has been set. Because each data bit has it's own clock pulse, the hardware is tolerant of a wide range of transmission speeds and I assume that I can always slow the transmission down with some kind of Pause instruction or routine if the Arduino runs too fast. The PICAXE, running at a 4 MHz clock gave me no problems: I actually wanted it to run faster. I believe the Uno will be significantly faster. The data transmitted will consist of one 8 bit data word and 6 additional bits, 3 before the data word and 3 after. These bits will be constant except for the third one in the leading group. The pattern, in order of transmission, looks like this: 1 0 ? b7 b6 b5 b4 b3 b2 b1 b0 0 0 0. This sequence is fixed in the hardware and would be quite difficult to change at this point.

For the PICAXE I used subroutines. I started with two, one for each choice of the third bit. Once that third bit was set, these two subs then passed control to a third sub which actually transmitted the full 14 bits. Subroutines are probably the only way to do it for that processor due to it's simplicity. And there are a couple of additional subs for some necessary housekeeping: five all totaled.

The main part of the PICAXE program then simply called these subs with the appropriate data to demonstrate the various uses of the hardware.

At this point I would like to ask for some thoughts as to how this type of thing could/should best be accomplished on the Arduino. I assume that I could follow the PICAXE model and just use subroutines. But, as I understand it, C++ has a feature called library files. So I wonder if they could be used to create the communication routines? Or perhaps there is another way? What would be the best approach? What approach would you prefer if you were purchasing this device and it's software? Which would be the easiest for the user to learn and use? And, which would be possible for an inexperienced C++ programmer, like myself, to be successful in creating?

One more thing, I AM completely aware of other serial communication protocols, like I2C. These were considered when the hardware was being designed. However, they were rejected for a number of reasons. One of which was the requirement for compatibility with as many microprocessors/PICs as possible. Another one was to allow at least one of the lines/pins used to serve for additional purposes when pins were in short supply. The scheme chosen will allow the data pin to be used for other devices as long as the clock pin is not pulsed. And there were others, so the hardware is really fairly fixed at this point and the communication method I described above will probably be the final one used.

What I get from your long post is that you need a system on the Arduino that outputs data bits on one pin while another pin acts as a clock.

Sounds like it might need 8 or 10 lines of code.

So maybe I am missing your question completely?

...R

Please do not ask for all the specifics as it is proprietary. I will provide as much as I believe is needed and as I can

Start by reading the sticky at the top of the forum. Where is your code. Post it all of it.

As this is a commercial project what pay are you offering?

By the way WE decide what information is required in order to answer a question, NOT you!. The answer to your question however is that the hardware has been missed designed and therefore needs to be scraped and redesigned!.

Mark

Robin2:
What I get from your long post is that you need a system on the Arduino that outputs data bits on one pin while another pin acts as a clock.

Sounds like it might need 8 or 10 lines of code.

So maybe I am missing your question completely?

...R

Well, it very well may be just that. I am not asking for specific code; I could probably cobble out something that would work with my present, very limited knowledge of both Arduino and C++.

Since I am not at all familiar with the overall Arduino environment, what I am asking is what is the best general approach? Philosophy, not specifics. Should I use subroutines? Or create a library? Or something else?

holmes4:

Please do not ask for all the specifics as it is proprietary. I will provide as much as I believe is needed and as I can

Start by reading the sticky at the top of the forum. Where is your code. Post it all of it.

As this is a commercial project what pay are you offering?

By the way WE decide what information is required in order to answer a question, NOT you!. The answer to your question however is that the hardware has been missed designed and therefore needs to be scraped and redesigned!.

Mark

I did read the stickies. And I have posted ALL the code that I have written. I am looking for GENERAL guidance before even attempting to write any code. Perhaps this approach is too professional for you, but it has served me well when designing and producing systems in the past.

I was under the impression that this BB is a group of users who help each other, not a commercial service where payment is expected. Perhaps I should have hidden the commercial nature of this project, but I thought it best to be honest and up front. I may be new here, but can assure you that I participate in many web BB where there is never any thought of compensation for advice that is offered weather it be for personal or for commercial projects. Besides, just how many of the requests for help on here are PURELY for personal use only? Anybody have that figure? I won't hold my breath. If you don't want to help in a commercial project, you are free to not do so.

As for the amount of information I have given here and the hardware design, I am constrained to avoid posting the full details of the project. If you feel that you can not help with the limited amount, then please allow others to consider doing so. On the hardware, since you know very little about it, I doubt that you can make any proper judgment about it's suitability. You will just have to take my word that due consideration was given to other designs. Probably too much consideration. Cost was a very important factor in this. If you are in the USA and are competing with the Chinese labor rates, you MUST keep things as inexpensive as possible. This is much more important in a commercial product than for a personal project. Again, if you feel that you can not offer any help with these constraints, please step back and perhaps allow others to do so.

Again, I am not asking for code. Just suggestions on the general approach. I will write the code and only ask questions if I get stuck. If/when that happens, I will post the relevant code.

ChipsNChips:
Since I am not at all familiar with the overall Arduino environment, what I am asking is what is the best general approach? Philosophy, not specifics. Should I use subroutines? Or create a library? Or something else?

The Arduino doesn't care how you organize your code. I get the impression you know how to program a PIC - why do you imagine an Arduino would be significantly different. Just write code.

The only philosophies I try to work with - in order of priority - are ( A ) does it work properly ( B) will I understand the code with a single read-through after not having seen it or thought about it for 6 months and ( C ) [which is part of B] keep it simple.

...R

I skimmed through your post. I seems like your making drivers to operate some hardware that I'm thinking the user would run using your libraries with his/her Arduino?

Seeing that it proprietary, wouldn't it be a bad thing to show the world your source code of the completed drivers? I ask because everything I've seen on the Arduino is full source code. For example, I have an Adafruit touch screen and all the drivers are just source for everyone to see.

Would this factor in to your decision?

-jim lee

Some amount of secrecy is needed during the development phase as this is a product that would be fairly easy to duplicate. And we fear that there are a number of persons and companies that could and would do so in fairly short order, perhaps faster than we can complete the development stage. So we are primarily trying to just be the first ones on the market.

Once the product is on the market, all the details will be available to anyone who cares to spend a relatively small amount to purchase one. It will be sold in kit form with schematics and complete instructions. Very well documented/commented code for several different PIC devices will be posted on the internet for all to view, copy, and use. Our hope is to establish a reputation and base of sales before the inevitable rip-offs.

If we can sell it at a low enough price point, perhaps others will hesitate to copy it. But what will be, will be.

Your comments make me wonder, is there any additional security gained by placing the operational routines in a library?

CnC

jimLee:
I skimmed through your post. I seems like your making drivers to operate some hardware that I'm thinking the user would run using your libraries with his/her Arduino?

Seeing that it proprietary, wouldn't it be a bad thing to show the world your source code of the completed drivers? I ask because everything I've seen on the Arduino is full source code. For example, I have an Adafruit touch screen and all the drivers are just source for everyone to see.

Would this factor in to your decision?

-jim lee

Would it be easier to just write your stuff in c?

Maybe… And that can be your library.

sendByte(byte data, boolean thirdBit);

Or at least the start of your library. From what I read here, everything you plan on doing would be calls to a routine like this. Or is there some complex set of states that need to be kept track of for these calls? Like, for example, a network protocol stack.

-jim lee

Since this is going to be a professional and commercial product then a proven coding template methodology might be your first port of call.

When working between platforms one would normally abstract the code.

You need to be thinking about HALs (Hardware Abstraction Layers) that communicate with the chosen hardware platform exposing a set of methods though a binary interface that can be consumed by the other layers.

This way your other layers dont know or care about what hardware they are running on and you can have a considerable amount of platform independent code shared between the platforms.

If you want to expand on this then feel free to PM me.

Cheers Pete.

The product is the hardware. When the product is released for sale, the code will be provided to all with no conditions in order to assist with sales. The secrecy is only during the development time as it would be very easy for others to copy the design. It is a low cost, low profit product and not worth the cost of a patent and the expenses of defending against infringement. Our hopes are to get it established as the original developer, with the best support and that copies would not be as attractive. We simply want a head start on those inevitable copies.

ChipsNChips:
Some amount of secrecy is needed during the development phase as this is a product that would be fairly easy to duplicate. And we fear that there are a number of persons and companies that could and would do so in fairly short order, perhaps faster than we can complete the development stage. So we are primarily trying to just be the first ones on the market.

Once the product is on the market, all the details will be available to anyone who cares to spend a relatively small amount to purchase one. It will be sold in kit form with schematics and complete instructions. Very well documented/commented code for several different PIC devices will be posted on the internet for all to view, copy, and use. Our hope is to establish a reputation and base of sales before the inevitable rip-offs.

If we can sell it at a low enough price point, perhaps others will hesitate to copy it. But what will be, will be.

Your comments make me wonder, is there any additional security gained by placing the operational routines in a library?

CnC

jimLee:
I skimmed through your post. I seems like your making drivers to operate some hardware that I'm thinking the user would run using your libraries with his/her Arduino?

Seeing that it proprietary, wouldn't it be a bad thing to show the world your source code of the completed drivers? I ask because everything I've seen on the Arduino is full source code. For example, I have an Adafruit touch screen and all the drivers are just source for everyone to see.

Would this factor in to your decision?

-jim lee

ChipsNChips:
The product is the hardware. When the product is released for sale, the code will be provided to all with no conditions in order to assist with sales. The secrecy is only during the development time as it would be very easy for others to copy the design. It is a low cost, low profit product and not worth the cost of a patent and the expenses of defending against infringement. Our hopes are to get it established as the original developer, with the best support and that copies would not be as attractive. We simply want a head start on those inevitable copies.

So do you want to pay for help or not ?

Personal I dont care what you do with code once you have paid for it.

PM me if you want to take this past the "talking about it" to "actually doing something" stage.

You can check out my credentials and abilities at WWW.EmbeddedAT.com

Cheers Pete.