# Arduino/micro-controller thread

**URL:** <https://boards.straightdope.com/t/arduino-micro-controller-thread/727568>\
**Category:** Miscellaneous and Personal Stuff I Must Share\
**Created:** [August 11, 2015, 5:07pm UTC](https://boards.straightdope.com/t/arduino-micro-controller-thread/727568 "2015-08-11T17:07:49Z")\
**Posts on this page:** 14\
**Page:** 3

<div class="post-metadata">

**Author:** ![Dr.Strangelove](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/dr.strangelove/32/6613_2.png) [@Dr.Strangelove](https://boards.straightdope.com/u/Dr.Strangelove)\
**Post date:** [August 24, 2015, 10:41pm UTC](https://boards.straightdope.com/t/arduino-micro-controller-thread/727568/41 "2015-08-24T22:41:07Z")

</div>

> [@CinnamonBabka](#):
>
> From my several seconds of googling I don’t think the RPi is even $10 more than the Arduino.

RasPi is ~$30. An Arduino Nano knockoff is \<$5 shipped.

> [@CinnamonBabka](#):
>
> Toggling the GPIO on an RPi is [simple enough](https://github.com/ams-tech/lkm/blob/master/modules/meters/common/src/meter_phy.c) to do in a kernel module.

It does seem to have gotten a lot easier since I last looked at it. Check out [this page](http://codeandlife.com/2012/07/03/benchmarking-raspberry-pi-gpio-speed/) on GPIO perf. It’s actually somewhat fast with the native C library. All the other language bindings (shell/Python/Perl/Ruby) are totally hopeless, though. I implemented a 115k serial port on a 1 mips PIC; being unable to match that is just hilariously bad. 22 MHz is not quite _impressive_, but acceptable.

---

<div class="post-metadata">

**Author:** ![CinnamonBabka](https://avatars.discourse-cdn.com/v4/letter/c/bbce88/32.png) [@CinnamonBabka](https://boards.straightdope.com/u/CinnamonBabka)\
**Post date:** [August 25, 2015, 3:17pm UTC](https://boards.straightdope.com/t/arduino-micro-controller-thread/727568/42 "2015-08-25T15:17:59Z")

</div>

Wow, that’s a larger cost delta than I thought.

For any kind of hardware interactions on the RPi I’d write a kernel module to drive the appropriate [chip peripheral](http://www.farnell.com/datasheets/1521578.pdf) rather than attempt to drive GPIO from userspace. From a quick glance (and we all know how accurate my quick glances are) it looks like the SPI controller can run up to 125MHz.

---

<div class="post-metadata">

**Author:** ![Dr.Strangelove](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/dr.strangelove/32/6613_2.png) [@Dr.Strangelove](https://boards.straightdope.com/u/Dr.Strangelove)\
**Post date:** [August 25, 2015, 8:23pm UTC](https://boards.straightdope.com/t/arduino-micro-controller-thread/727568/43 "2015-08-25T20:23:53Z")

</div>

> [@CinnamonBabka](#):
>
> I’d write a kernel module to drive the appropriate [chip peripheral](http://www.farnell.com/datasheets/1521578.pdf) rather than attempt to drive GPIO from userspace.

I’m impressed, but I think you might have discovered why Arduinos are popular :).

How painful is development of kernel modules, anyway? My only experience is on Windows, where it’s not too bad, but certainly more annoying than userspace. I assume Linux supports dynamic module loading so you don’t have to restart the OS? Are there GUI kernel debuggers available?

---

<div class="post-metadata">

**Author:** ![TriPolar](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/tripolar/32/3008_2.png) [@TriPolar](https://boards.straightdope.com/u/TriPolar)\
**Post date:** [August 25, 2015, 8:58pm UTC](https://boards.straightdope.com/t/arduino-micro-controller-thread/727568/44 "2015-08-25T20:58:21Z")

</div>

> [@Dr.Strangelove](#):
>
> Last night, circa 3 am: I find an off-by-1 error in one of my programs. I wrote the code in question like a year ago. “How did this _ever_ work?”
> 
> I don’t think you’re a real programmer until you’ve exclaimed those words in the wee hours of the morning.

Just a couple of weeks I ago I decided to ‘save time’ by re-using some old code. Same kind of problem, finally after spending twice as long as it would have taken to re-write from scratch I realized the old code never had to initialize the list it was maintaining.

---

<div class="post-metadata">

**Author:** ![CinnamonBabka](https://avatars.discourse-cdn.com/v4/letter/c/bbce88/32.png) [@CinnamonBabka](https://boards.straightdope.com/u/CinnamonBabka)\
**Post date:** [August 25, 2015, 9:07pm UTC](https://boards.straightdope.com/t/arduino-micro-controller-thread/727568/45 "2015-08-25T21:07:33Z")

</div>

> [@Dr.Strangelove](#):
>
> I’m impressed, but I think you might have discovered why Arduinos are popular :).

I’d be surprised if there aren’t any tools out there to simplify the process on the RPi, but when you’re armed with a hammer of a [textbook](https://lwn.net/Kernel/LDD3/) all of your problems start to look like they need to be solved in the kernel.

> [@](#):
>
> How painful is development of kernel modules, anyway?

Depends on your definition of painful. I’m writing character device drivers, so the interface with userspace is done via a [file operations](https://github.com/ams-tech/lkm/blob/master/modules/meters/common/src/meter_fops.c) structure. Safely accessing userspace memory and peripheral registers requires a few API calls as well.

> [@](#):
>
> I assume Linux supports dynamic module loading so you don’t have to restart the OS?

Yes, provided your driver doesn’t break the system and can load/unload cleanly. I needed to reboot the system a few times early on when I was learning what the hell I was doing.

> [@](#):
>
> Are there GUI kernel debuggers available?

I’ve done all of my debugging with printk! There are debuggers out there, but so far I haven’t had the need to use them.

---

<div class="post-metadata">

**Author:** ![friedo](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@friedo](https://boards.straightdope.com/u/friedo)\
**Post date:** [August 25, 2015, 9:22pm UTC](https://boards.straightdope.com/t/arduino-micro-controller-thread/727568/46 "2015-08-25T21:22:03Z")

</div>

> [@CinnamonBabka](#):
>
> I’d be surprised if there aren’t any tools out there to simplify the process on the RPi, but when you’re armed with a hammer of a [textbook](https://lwn.net/Kernel/LDD3/) all of your problems start to look like they need to be solved in the kernel.

I had a problem.

So I wrote a kernel driver.

Now I have −2,147,483,648 problems.

---

<div class="post-metadata">

**Author:** ![CinnamonBabka](https://avatars.discourse-cdn.com/v4/letter/c/bbce88/32.png) [@CinnamonBabka](https://boards.straightdope.com/u/CinnamonBabka)\
**Post date:** [August 25, 2015, 9:25pm UTC](https://boards.straightdope.com/t/arduino-micro-controller-thread/727568/47 "2015-08-25T21:25:57Z")

</div>

> [@friedo](#):
>
> I had a problem.
> 
> So I wrote a kernel driver.
> 
> Now I have −2,147,483,648 problems.

I haven’t seen a joke that funny since I canceled my subscription to Sensible Chuckle.

---

<div class="post-metadata">

**Author:** ![Robot\_Arm](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/robot_arm/32/18280_2.png) [@Robot\_Arm](https://boards.straightdope.com/u/Robot_Arm)\
**Post date:** [August 26, 2015, 10:06am UTC](https://boards.straightdope.com/t/arduino-micro-controller-thread/727568/48 "2015-08-26T10:06:03Z")

</div>

> [@LSLGuy](#):
>
> These two quotes aren’t related, but …
> 
> **Robot Arm** ’s victory cry and bed-going was at 6:52AM. Despite **Babka** ’s happy assertions about the wonders of this most modern of ages, I’m reminded that some aspects of programming haven’t changed since I was in college in the 70s, nor as a sporadic developer through the 80s, 90s, '00s, and even early '10s.
> 
> The more things change, the more they stay the same! 😃

It’s not that I’ve been putting in a lot of hours on this project, I’m just a huge night owl.

Progress continues. I’m starting to plot out what I’ll have to do to draw text. I’ve got a capital ‘H’, but it’s still pretty wonky. I had a test program drawing a circle, and even when I tried to return to the starting coordinates (1 unit being 1 step of either the x or y motor) it wouldn’t close the loop. It could be that I’ll never be able to logically account for the slack in the system. I may have to massage my drawing coordinates by hand until the result looks right.

> [@Dr.Strangelove](#):
>
> Last night, circa 3 am: I find an off-by-1 error in one of my programs. I wrote the code in question like a year ago. “How did this _ever_ work?”
> 
> I don’t think you’re a real programmer until you’ve exclaimed those words in the wee hours of the morning.

> [@LSLGuy](#):
>
> It seems I’ve been a “real programmer” for a very long time. You can tell I’ve just been reading the “Age and related horrors” thread.

A real programmer? I give you [The Story of Mel](https://www.cs.utah.edu/~elb/folklore/mel.html).

---

<div class="post-metadata">

**Author:** ![Sage\_Rat](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/sage_rat/32/399_2.png) [@Sage\_Rat](https://boards.straightdope.com/u/Sage_Rat)\
**Post date:** [August 26, 2015, 12:01pm UTC](https://boards.straightdope.com/t/arduino-micro-controller-thread/727568/49 "2015-08-26T12:01:43Z")

</div>

> [@Robot\_Arm](#):
>
> A real programmer? I give you [The Story of Mel](https://www.cs.utah.edu/~elb/folklore/mel.html).

We just don’t code like that no more!

In a thread on parsing UTF-8, I did come up with the shortest code of the thread, when compiled to assembler. That made me happy.

---

<div class="post-metadata">

**Author:** ![LSLGuy](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lslguy/32/5813_2.png) [@LSLGuy](https://boards.straightdope.com/u/LSLGuy)\
**Post date:** [August 26, 2015, 12:24pm UTC](https://boards.straightdope.com/t/arduino-micro-controller-thread/727568/50 "2015-08-26T12:24:38Z")

</div>

> [@friedo](#):
>
> I had a problem.
> 
> So I wrote a kernel driver.
> 
> Now I have −2,147,483,648 problems.

> [@Robot\_Arm](#):
>
> It’s not that I’ve been putting in a lot of hours on this project, I’m just a huge night owl.  
> …  
> A real programmer? I give you [The Story of Mel](https://www.cs.utah.edu/~elb/folklore/mel.html).

Awesome. Kudos to both of you.

And as to the part of **Robot Arm** ’s post that I snipped, yeah: almost all the true kludgetastic evils live in the cracks where the pure digital world connects to that nasty real world of, cough, moving parts. Good luck creating a compact yet accurate correction function for gear lash & cable slack. I can send you a few quarts of midnight oil if you’d like. 🙂

---

<div class="post-metadata">

**Author:** ![Robot\_Arm](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/robot_arm/32/18280_2.png) [@Robot\_Arm](https://boards.straightdope.com/u/Robot_Arm)\
**Post date:** [August 29, 2015, 5:07am UTC](https://boards.straightdope.com/t/arduino-micro-controller-thread/727568/51 "2015-08-29T05:07:39Z")

</div>

> [@Dr.Strangelove](#):
>
> Excellent! I want to see videos when you’re done.

No video yet, but I’ve got some still pictures.

> **[Paste@Muppetlabs » Welcome!](https://www.muppetlabs.com/pastebin/)**
>
> A quick, simple, multi-purpose pastebin.

[![](https://www.muppetlabs.com/~eric/EAS2.jpg) ](https://www.muppetlabs.com/~eric/EAS2.jpg)  
[![](https://www.muppetlabs.com/~eric/EAS3.jpg) ](https://www.muppetlabs.com/~eric/EAS3.jpg)

---

<div class="post-metadata">

**Author:** ![TriPolar](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/tripolar/32/3008_2.png) [@TriPolar](https://boards.straightdope.com/u/TriPolar)\
**Post date:** [August 29, 2015, 3:32pm UTC](https://boards.straightdope.com/t/arduino-micro-controller-thread/727568/52 "2015-08-29T15:32:52Z")

</div>

I love the use of the window latch!

---

<div class="post-metadata">

**Author:** ![Robot\_Arm](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/robot_arm/32/18280_2.png) [@Robot\_Arm](https://boards.straightdope.com/u/Robot_Arm)\
**Post date:** [August 29, 2015, 7:26pm UTC](https://boards.straightdope.com/t/arduino-micro-controller-thread/727568/53 "2015-08-29T19:26:13Z")

</div>

> [@TriPolar](#):
>
> I love the use of the window latch!

Thanks. I was walking through Lowe’s and looking for something that would hold the Etch-A-Sketch in place, and I just stumbled on it.

The original plan was to be able to be able to swap the E-A-S in and out easily. That may be less of a priority than I thought.

---

<div class="post-metadata">

**Author:** ![TriPolar](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/tripolar/32/3008_2.png) [@TriPolar](https://boards.straightdope.com/u/TriPolar)\
**Post date:** [September 4, 2015, 2:55am UTC](https://boards.straightdope.com/t/arduino-micro-controller-thread/727568/54 "2015-09-04T02:55:46Z")

</div>

The Arduino kit finally showed up. Maybe I’ll have some time for this over the weekend. The kit includes an accelerometer, rotary encoder, and an 8X8 dot matrix display, so I can play around for a while until I think of some frustrating project that will keep me up all hours of the night.

[Previous page](https://boards.straightdope.com/t/arduino-micro-controller-thread/727568.md?page=2)
