You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

138 lines
7.4 KiB

\documentclass[11pt]{article}
%Gummi|065|=)
\usepackage{graphicx}
\usepackage{caption}
\usepackage{xcolor}
\usepackage[vcentering,dvips]{geometry}
\geometry{papersize={6in,9in},total={4.5in,6.8in}}
\title{\textbf{UserSpace IO via uLisp and Arduino Uno}}
\author{Steak Electronics}
\date{}
\begin{document}
\maketitle
%\tableofcontents
\textcolor{green!60!blue!70}{
\section{UserSpace IO via uLisp and Arduino Uno}}
Overview: Goal is to get an easy way to echo "command" \textgreater
/dev/ARDUINO from GnuLinux userspace.
Then I can 3D print a box, throw some LEDs in there, and get a hardware interface for anything from my distro.
\\
\subsection{Setup}
First off, I installed the stable uLisp from ulisp.com (AVR version 3.4 in 2020/12). \footnote{It's a sketch. It installs from Arduino IDE (must be reasonably recent, so 1.8 from Arduino.com works, but not Beowulf/Buster's 1.0 Arduino).}
\subsubsection{Trouble with interfacing directly to
ttyACM0} The Arduino Uno uses an FTDI USB to Serial chip. It also has more than just RX/TX connected (I think). This means
that when you echo "something" to arduino, this command will open the serial connection, send the command, then close the command and
possibly reset the board via one of the UART reset pins (DTS perhaps). This won't work. First thing to do, get an FTDI board, and
connect it to the computer, the connect it to digital pins 0,1 (for UART). Then test sending a command. This works. This will be the
final setup. Computer -\textgreater FTDI -\textgreater Arduino.
It should be possible to get it to work without the FTDI chip, but not without some debugging. Have at it, if you wish. I don't have
time to troubleshoot this now. I tried a few things (exec 3\textless \textgreater, and the stty) neither worked. You could also use Python, but then that's
more dependencies. Bad idea. This should be simple.
Ref:
https://forum.arduino.cc/index.php?topic=61127.0
https://arduino.stackexchange.com/questions/16776/how-to-connect-arduino-device-to-linux
https://stackoverflow.com/questions/3918032/bash-serial-i-o-and-arduino
\subsubsection{Troubleshooting Code}
The first thing you will want to do is prove that you can echo or cat "code" \textgreater /dev/ARDUINO.
This code works:
\begin{verbatim}
(defun b (&optional x)
(pinmode 13 :output)
(digitalwrite 13 x)
(delay 1000)
(b (not x)))
(b)
\end{verbatim}
Save it as a text file, then cat the file into /dev/ttyUSB0 or /dev/ARDUINO. Problem is, the code runs
indefinitely. You can't tell it to do anything else. Hit the reset button to restart the Uno back to square one. So instead, you want a
function that runs and then stops. Here's one of those:
\begin{verbatim} (defun b ()
(pinmode 13 :output)
(digitalwrite 13 nil)
(delay 500)
(digitalwrite 13 t)
(delay 200)
(digitalwrite 13 nil)
(delay 500)
(digitalwrite 13 t)
(delay 200)
(digitalwrite 13 nil)
(delay 500)
(digitalwrite 13 t)
(delay 200)
(digitalwrite 13 nil)
(delay 500)
(digitalwrite 13 t)
(delay 200))
(b)
\end{verbatim}
This works. Save it as a .dat or .txt (whatever) and cat file.txt \textgreater /dev/ARDUINO. It will blink a few times, then
stop. You can cat it again, if you wish. There, now we have an interface, and we have proven we can switch an IO high/low. With a couple
of functions, it's trivial to build an interface.\footnote{i.e. have one function set IO high for a given pin. Have one function set IO low.
Have one function blink IO some amount of times. This can be used for counters or shift registers, or in the former, just controlling GPIO.}
Tip: When building code, copy and paste into the Arduino Serial Monitor first. This way, if there's an error, it will tell you what's
wrong. After you've tested the code, then you can put it in a text file. As we are keeping this simple, we don't have logging setup, or
anything else. This is meant to be for basic IO from user space, not C compiled programs. Think lightweight. Fast. Fun.
\subsection{An interface for basic GPIO}
Now, let's build an API/interface so that we can flip some IO, and perhaps increment as mentioned.
\begin{verbatim}
let's ask this: what do I want to accomplish?
answer: I want to be able to flash leds from user space.
possibly increment a counter, but
that's later. for now, just flash leds.
solution: build box / board for uno. connect everything up.
build initialization program
(that will enable outputs as high)
Then find a way to send commands from gnulinux. let's begin.
1. build initialization program
2. create enclosure, and wire up leds
3. run program live from gnuLinux.
\end{verbatim}
--
\subsection{Countersunk Magnets}
This is a bit of a sidestory from another project, but since I'm already putting 2020's electronics projects into a book, I can't edit those documents. In 2020, I have a project that covers Attiny10 protoboard and setup. The goal is a wireless sensor. In 2020 I also toredown an Edimax Wireless AP. What is notable is that the WAP had countersunk magnets. Countersunk is essentially that there is a hole in the magnet for a screw to go \footnote{This is an oversimplification, as there is also counterbore, which is similar to countersunking but without the gradient according to wikipedia, but for our practical intents and purposes, countersunk magnet means, ``screw hole in middle where you can attach somewhere''. That's the term that it represents online in stores. If I had time, I'd put a picture of a countersunk magnet on the wiki page.}.
This term refers to both the rectangular pieces you would screw into drywall or concrete, and also to the circular pieces that you would put into your enclosure/box. Looking at the WAP1750 design, you simply put a hole on the bottom of the box, for a threaded insert, use an iron to attach the threaded insert quickly, then screw the magnet into the insert. I see a lot of 3mm countersunk magnets, so either \#4 or 3mm screws can be used.
Prices are reasonable, but not free. I see a pack of 50 qty. countersunk magnets for about \$6.50. That's close to 10 cents per magnet. My boxes will use two, so that's about 25 cents for these magnets per box. These are industrial sensors, so I think it's acceptable.
However, the rectangular parts are more expensive. These look to be about \$2 each minimum. More research needed.
Why use magnets to mount your box to the wall? It makes removal and maintenace of the box much, MUCH easier. There is no going back. No more screwing to the wall, and you don't even have to remove it from a bracket. If you can put magnets in your device without interfering with the circuitry, I think it's an obvious choice.
Some other products / cameras use this. During my search I found for example, the Netgear Arlo that has a rounded magnet mount for its camera. The camera can be adjusted anywhere in a 180 degree radius around the round mount. This is not necessary for the application that I'm using, but it's a novel idea. The mounts are available online, at about \$7 each. Ouch.
So if price is an issue, you use a cheap plastic bracket, and screw the bracket into the drywall / concrete, place the box in the bracket. But magnets, are much more functional, if you can get them, and they don't interfere.\footnote{They'll even allow attaching the wireless battery powered sensors to anything that is magnetic metal. That saves the need for the rectangular part, but make sure you get the poles right.}
%pictures of wap mounts
\end{document}