- Posts: 56
- Thank you received: 5
Arduino [or other uCPU] controlled.....
- TheWag
- Offline
- New Member
markm wrote: I've looked at both sites, and a few others, plus 3 or 4 books. While I wouldn't discourage anyone from using them, they all look a lot alike with the same examples and similar commentary and they all seem to miss the fact that programming a microcontroller is different than a microprocessor (PC) and the subilites they miss can make a big difference in the success of a program.
There is part of the difference. The "Arduino" method is to remove complexity. Make it more "accessible" to the masses. Don't get caught up in technicalities. That is also why there IDE is designed for a setup and loop and removes the main() construct. It is interesting to lurk on the dev list and see how they try to hide the complexity.
Personally I hate the way the IDE is designed and use my own makefiles.
I'm also curious as to your example. I'm curious as to why you'd prefer one method of the other on the uC. You mention a lot of experience. I'd love some pointers from a master.
Ben
Please Log in or Create an account to join the conversation.
- markm
- Offline
- Senior Member
- Posts: 293
- Thank you received: 69
Ben,
I'm impressed with what the Arduino people have done in putting a wrapper around the Atmel software and hardware, but there are fundamental differences between development of a computer program and a uC project:
For the uC you are building and debugging the software and hardware at the same time. If the project doesn't work you can be hard to debug.
Microcontrollers have limited resources and you always need to keep that in mind. In the case of the UNO I have, that limit is 31K of program memory, 2K of volatle data memory and 1K of non-volatle data memory.
So I'm a strong advocate of defensive programming and like to see it taught as a basic concept.
As far as the examples, the int led = 13; code creates a read/write variable, 2 bytes in length that can be modified anywhere in the program, which defines a device pin that can range from -32K to + 32K, which is a bit silly.
So unless your intent is to change the pin number in the program, its much safer to add the const , and make the variable read-only. The compiler will complain if you accidently try to change the variable.
Add the unsigned to eliminate the possiblity of negative pins numbers.
Change the varible size from int to byte which limits the range of the pin number to 0-255. This also reduces the blink program size from 1084 bytes to 1076.
So the optimum code for blink would be
const byte led = 13;
The #define does a string substitution of "13" for "led" everywhere in the program before compile,which can be useful but can make a real mess if not used carefully and I would advise beginners to avoid it.
I don't think the defensive programming concepts of making numbers no bigger than necessary and making the number read/write only when you intend to change them difficult, although I'd like to hear opinions about this explaination.
Mark
Please Log in or Create an account to join the conversation.
- Zcratchman_Joe
- Offline
- Senior Member
- Posts: 281
- Thank you received: 41
Mark,markm wrote: ...although I'd like to hear opinions about this explaination.
Mark
I believe there’s a time for “tight” (concise) code, and a time for “right” (proper) code. What I mean by this, is that when programming with size/memory constraints, tighter code, that may be a bit dangerous, may be needed over what might be a more proper way to do things.
In this example, your code not only tightened things up, but also righted what could be considered improper coding for the intended purpose.
Re: Ben’s post previous to this one mentioning an IDE. It’s been mentioned elsewhere in this thread about things sounding like “geekspeak”. A lot of non-technical folks might have only heard the term IDE when referring to a type of hard drive or CD/DVD-ROM (Integrated Drive Electronics) which would make no sense in the context it was used here (Integrated Development Environment). [Don’t take offense Ben, “geekspeak” is used throughout this thread and I only used IDE because of its many meanings.]
When we’re talking about techy stuff on a non-techy forum, we have to remember that the people that ask for the help here are more than likely clueless to the meaning of the majority of what the tech-savvy people are discussing. It’s easy to write about things with terminology we might be used to using, but more than likely there’s another way to say the same thing (using the long drawn out boring terminology that others might just understand.) It’s something to keep in mind anyway.
Joe
Please Log in or Create an account to join the conversation.
- Kelley
- Offline
- Dispatcher
- Posts: 764
- Thank you received: 73
Thanks guys for talking this out. I am wondering if you all could set something up and show what hard ware to get, how to wire it up and how to program it here.
I have some lighted cross bucks, and they will be used on double tracks. I would like to activate them, have them blinking (simulated incandescent) and a bell go off and on automatically.
These little processors things could be their own forum topic, and would be useful for a LOT of people. I appreciate you guys replying and all the feedback!
Please Log in or Create an account to join the conversation.
- Zcratchman_Joe
- Offline
- Senior Member
- Posts: 281
- Thank you received: 41
Kelly, actually someone has already done “just about” what you ask. Please carefully read through and try the tutorial I suggested earlier ( www.ladyada.net/learn/arduino/index.html ). It tells you exactly what you asked for here and after you get through, say Lesson 3, you could try cut and pasting in the code Mark posted earlier (post #15081). By then you’ll have learned a bit on your own as well, and all for a total cost of around $75.00 including the Arduino (but not any tools you may need and probably already have anyway). Then, for a start, you can Google “Arduino sketches for model railroading”. You’ll find there are websites and forums devoted to such things for when you get stuck, plus by then I’m sure there are others here that can help you.Kelley wrote: ...I am wondering if you all could set something up and show what hard ware to get, how to wire it up and how to program it here...
Joe
Please Log in or Create an account to join the conversation.
- markm
- Offline
- Senior Member
- Posts: 293
- Thank you received: 69
Since I'm planning to do a crossing signal with detection and block control, I'd be willing to document the project and discuss it here if there is interest. I would suggest people look at the ladyada site LED chapter to get a feeling for what will be needed in construction skills supllies and equipment before getting involved.
I haven't mention my current project yet. It's a Christmas animation. A small train goes around a 24" oval passing by a small mountain village with a station. Using a 24 hr fast clock, every so often, a semaphore stops the train at the station for passengers. As 5PM rolls around, the lights flicker on at the town square with a lighted Christmas tree, come on at the station and in the local houses. As time passes the lights go out in the station and on in the stationmaster's quarters, the fires are lit and die down, which the bedroom light coming on and going out. Using the night, when the train is going to stop at the station, the lights go back on in the station quaters and in the station proper, after the train leaves, the lights go out. As "morning" arrrives lights in the houses come on as the "sun comes up" all lights go out.
Mark
Please Log in or Create an account to join the conversation.
- Kelley
- Offline
- Dispatcher
- Posts: 764
- Thank you received: 73
Please Log in or Create an account to join the conversation.
- elafargue
- Offline
- New Member
- Posts: 1
- Thank you received: 0
Since the project took a not so insignificant amount of time, I have decided to document it on my blog, at www.aerodynes.fr
, in a series of about 12 articles, that describe the whole thing, from hardware design all the way to the HTML5 web app. Everything is published on github as well.
Attached, a few screenshots of the interface, hoping this be interesting for some of you!
Please Log in or Create an account to join the conversation.
- stonysmith
- Offline
- Moderator
- Posts: 316
- Thank you received: 175
I need to go back and try the LM293 again.
Please Log in or Create an account to join the conversation.
- stonysmith
- Offline
- Moderator
- Posts: 316
- Thank you received: 175
hackaday.com/2013/08/14/controlling-a-railroad-with-an-mbed
Please Log in or Create an account to join the conversation.
- CreatorLes
- Offline
- New Member
- Posts: 6
- Thank you received: 6
One approach to automation of a railroad would be to avoid the ratsnest by using a communications bus with lots of the little wonders on it. Each one can be programmed with an address so that the master Arduino chip that humans communicate with through knobs and switches can send out commands and receive sensory input all using just four wires (power, ground, and two for I2C communication). Then you just program this little guy for your traffic light and this little guy runs a pair of swithches, etc. etc. to your heart's content.
I actually was going to start a music biz using these little wonders but it didnt' work out so now I've got 100+ little breakout boards for the chip that would give us three holes for each pin so solder resistors and wires, etc. I'd be happy to send some out for just the cost of postage, no charge, if someone or few folks would like to tinker with them. They do require a small $20 programmer board as well and the software to program them is free though a teeny bit tricky to install as I recall.
If interested, please give a shout!
Les
Please Log in or Create an account to join the conversation.
- Kelley
- Offline
- Dispatcher
- Posts: 764
- Thank you received: 73
Please Log in or Create an account to join the conversation.
- soccrdad30
- Offline
- Administrator
- Posts: 311
- Thank you received: 123
I know there are a handful of guys that are into programming the Arduino's. To what degree, I don't know.
Please Log in or Create an account to join the conversation.