Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > alt.os.linux > #53040
| From | Dan Purgert <dan@djph.net> |
|---|---|
| Newsgroups | alt.os.linux |
| Subject | OT (Code) Microcontroller Fun |
| Date | 2019-01-25 00:58 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <slrnq4knop.isj.dan@xps-linux.djph.net> (permalink) |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
In one of the (many) side-conversations fueled by our good friend
Arlen's ramblings, I made some comments about playing around with
Arduinos, as well as some of the bare chips that the various Arduino
boards are based on. And got a slightly positive response about them,
so thought I'd share a bit of my experiences with them.
This isn't going to be very linux-y, but there's apparently no
living microcontroller groups, and well, Arduino tends to focus on
Windows anyway ... so the "support" can be a bit light for Linux users.
If you've been thinking of grabbing one, do it. They're fun. The
sparkfun "Pro Mini" plus some header pins and the USB-to-RS232 adapter
will set you back about $20. (See below for links)
Since getting that first one, I've picked up a score of other bare
ATTiny chips (which all get programmed in situ by using that Pro Mini as
an ISP programmer), and around Christmas picked up one of the new
"1-series" demo boards.
That one's, well, difficult. On top of "not really focused on linux",
most of the people writing for it are writing in assembly. Joy.
Links
- -----
* Pro Mini - https://www.sparkfun.com/products/11113
* Headers - https://www.sparkfun.com/products/116
* Serial Breakout(micro-B) - https://www.sparkfun.com/products/14050
* Arduino IDE - https://www.arduino.cc/en/Main/Software
NOTE - if you're on any Debian-derived distro, the repos have a
godawful-old version of the Arduino IDE. Don't use it, just get 1.8.8
(or whatever happens to be current, if you're reading this after 2019)
directly from the site above.
Hope it goes without saying that you'll need a USB A to Micro-B cable as
well ... but then again, we do have the likes of Arlen in here.
You've got two options when writing for them:
1. "Arduino" code. Essentially C++ light (uses objects and a few
other things, but isn't really full C++
2. C89. Honestly, to me this just makes more sense -- the chips only
have a few kilobytes of flash space (the 'Tinies' that I've taken
a liking to come in 2,4, or 8 KiB variants; with some "lines"
also offering a 16 KiB variant).
Anyway, enough intro. Finally wrapped my head around the logic for the
demoboard after playing with it for ~3 weeks, and was able to make this
little blinken-led program. Long term goal for this guy is gonna be
running some signals and things on a model railroad.
BlinkenLED.c
=======================================================================
/*
* File: BlinkenLED.c
* Author: dan
*
* Various LED Tests, utilizing the onboard LED and button
* of a Microchip "xplained nano" ATTiny416 demoboard.
*/
#define F_CPU 3333333UL
#include <avr/io.h>
#include <util/delay.h>
//make this work more like arduino in terms of "pin names"
#include "chips.h"
int main(void) {
PORTB_DIRSET |= (1<<PB5); //output
PORTB_DIRSET &= ~(1<<PB4); //input
//enable input pullup
PORTB_PIN4CTRL |= 0b00001000;
PORTB_OUT |= (1<<PB5); //Make sure the LED is off
setup();
while (1) {
/*
//basic 1s on/of timed blink
PORTB_OUT &= (0<<PB5); //ON
_delay_ms(1000);
PORTB_OUT |= (1<<PB5); //OFF
_delay_ms(1000);
*/ //end timer
//Button Test. Turn LED ON when pressed
if (!(PORTB_IN & (1<<PB4))==1)
{
PORTB_OUT &= (0<<PB5); //ON
}
else
{
PORTB_OUT |= (1<<PB5); //OFF
}
_delay_ms(10); //delay 0.01 sec before looping to debounce
}
}
void setup() {
//setup - SOS blink to prove we flashed OK
_delay_ms(100);
PORTB_OUT &= (0<<PB5);
_delay_ms(100);
PORTB_OUT |= (1<<PB5);
_delay_ms(100);
PORTB_OUT &= (0<<PB5);
_delay_ms(100);
PORTB_OUT |= (1<<PB5);
_delay_ms(100);
PORTB_OUT &= (0<<PB5);
_delay_ms(100);
PORTB_OUT |= (1<<PB5);
_delay_ms(400);
PORTB_OUT &= (0<<PB5);
_delay_ms(500);
PORTB_OUT |= (1<<PB5);
_delay_ms(100);
PORTB_OUT &= (0<<PB5);
_delay_ms(500);
PORTB_OUT |= (1<<PB5);
_delay_ms(100);
PORTB_OUT &= (0<<PB5);
_delay_ms(500);
PORTB_OUT |= (1<<PB5);
_delay_ms(400);
PORTB_OUT &= (0<<PB5);
_delay_ms(200);
PORTB_OUT |= (1<<PB5);
_delay_ms(100);
PORTB_OUT &= (0<<PB5);
_delay_ms(200);
PORTB_OUT |= (1<<PB5);
_delay_ms(100);
PORTB_OUT &= (0<<PB5);
_delay_ms(200);
PORTB_OUT |= (1<<PB5);
}
========================================================================
It's not much, nor very complex, but it's a start.
-----BEGIN PGP SIGNATURE-----
iQEzBAEBCAAdFiEEBcqaUD8uEzVNxUrujhHd8xJ5ooEFAlxKXxgACgkQjhHd8xJ5
ooHVSgf/ReNCCBAqOVflnCfJSueLIhScOo8G5iDXVcne79Bk976XYOgUsnm/44e5
HpSGfIgLcdaaUUWyVMxzSQvzgVagDMx8F0eRb3tsgMdNtVMdTYZeccDxfPON7UYZ
Cd0dslv1FI5mLFaxGJbHgxdFdu0smoSJyRF4B7rM+rW8no6OWJYAeCk046v3u1yn
Wf7xKCWbEmfyNzlr0v482dPekDJ9LKyI1jULTRnzWmGwkoWXzgj+crOQdIZAYq3u
y23gA2tlpTHkrQ10o7Y/Xe2CEWO3PEvKfCvfM7X7aNtzkxxyoOC7LNkq3AJYtafy
ElRdDsfM4ATpI7k5RD5Gewu2hwUOrQ==
=oGCf
-----END PGP SIGNATURE-----
--
|_|O|_| Registered Linux user #585947
|_|_|O| Github: https://github.com/dpurgert
|O|O|O| PGP: 05CA 9A50 3F2E 1335 4DC5 4AEE 8E11 DDF3 1279 A281
Back to alt.os.linux | Previous | Next — Next in thread | Find similar | Unroll thread
OT (Code) Microcontroller Fun Dan Purgert <dan@djph.net> - 2019-01-25 00:58 +0000
Re: OT (Code) Microcontroller Fun ray carter <ray@zianet.com> - 2019-01-25 16:48 +0000
Re: OT (Code) Microcontroller Fun Ken Hart <kwhart1@frontier.com> - 2019-01-25 20:46 -0500
Re: OT (Code) Microcontroller Fun Paul <nospam@needed.invalid> - 2019-01-25 21:52 -0500
Re: OT (Code) Microcontroller Fun Dan Purgert <dan@djph.net> - 2019-01-26 13:08 +0000
Re: OT (Code) Microcontroller Fun John Hasler <jhasler@newsguy.com> - 2019-01-26 09:17 -0600
Re: OT (Code) Microcontroller Fun Ken Hart <kwhart1@frontier.com> - 2019-01-26 16:53 -0500
csiph-web