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.

119 lines
4.6 KiB

3 years ago
  1. \documentclass[11pt]{article}
  2. %Gummi|065|=)
  3. \usepackage{graphicx}
  4. \usepackage{caption}
  5. \usepackage{xcolor}
  6. \usepackage[vcentering,dvips]{geometry}
  7. \geometry{papersize={6in,9in},total={4.5in,6.8in}}
  8. \title{\textbf{UserSpace IO via uLisp and Arduino Uno}}
  9. \author{Steak Electronics}
  10. \date{}
  11. \begin{document}
  12. \maketitle
  13. %\tableofcontents
  14. \textcolor{green!60!blue!70}{
  15. \section{UserSpace IO via uLisp and Arduino Uno}}
  16. Overview: Goal is to get an easy way to echo "command" \textgreater
  17. /dev/ARDUINO from GnuLinux userspace.
  18. Then I can 3D print a box, throw some LEDs in there, and get a hardware interface for anything from my distro.
  19. \\
  20. \subsection{Setup}
  21. 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).}
  22. \subsubsection{Trouble with interfacing directly to
  23. ttyACM0} The Arduino Uno uses an FTDI USB to Serial chip. It also has more than just RX/TX connected (I think). This means
  24. that when you echo "something" to arduino, this command will open the serial connection, send the command, then close the command and
  25. 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
  26. 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
  27. final setup. Computer -\textgreater FTDI -\textgreater Arduino.
  28. 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
  29. 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
  30. more dependencies. Bad idea. This should be simple.
  31. Ref:
  32. https://forum.arduino.cc/index.php?topic=61127.0
  33. https://arduino.stackexchange.com/questions/16776/how-to-connect-arduino-device-to-linux
  34. https://stackoverflow.com/questions/3918032/bash-serial-i-o-and-arduino
  35. \subsubsection{Troubleshooting Code}
  36. The first thing you will want to do is prove that you can echo or cat "code" \textgreater /dev/ARDUINO.
  37. This code works:
  38. \begin{verbatim}
  39. (defun b (&optional x)
  40. (pinmode 13 :output)
  41. (digitalwrite 13 x)
  42. (delay 1000)
  43. (b (not x)))
  44. (b)
  45. \end{verbatim}
  46. Save it as a text file, then cat the file into /dev/ttyUSB0 or /dev/ARDUINO. Problem is, the code runs
  47. 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
  48. function that runs and then stops. Here's one of those:
  49. \begin{verbatim} (defun b ()
  50. (pinmode 13 :output)
  51. (digitalwrite 13 nil)
  52. (delay 500)
  53. (digitalwrite 13 t)
  54. (delay 200)
  55. (digitalwrite 13 nil)
  56. (delay 500)
  57. (digitalwrite 13 t)
  58. (delay 200)
  59. (digitalwrite 13 nil)
  60. (delay 500)
  61. (digitalwrite 13 t)
  62. (delay 200)
  63. (digitalwrite 13 nil)
  64. (delay 500)
  65. (digitalwrite 13 t)
  66. (delay 200))
  67. (b)
  68. \end{verbatim}
  69. This works. Save it as a .dat or .txt (whatever) and cat file.txt \textgreater /dev/ARDUINO. It will blink a few times, then
  70. 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
  71. 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.
  72. 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.}
  73. 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
  74. 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
  75. anything else. This is meant to be for basic IO from user space, not C compiled programs. Think lightweight. Fast. Fun.
  76. \subsection{An interface for basic GPIO}
  77. Now, let's build an API/interface so that we can flip some IO, and perhaps increment as mentioned.
  78. \begin{verbatim}
  79. let's ask this: what do I want to accomplish?
  80. answer: I want to be able to flash leds from user space. possibly increment a counter, but
  81. that's later. for now, just flash leds.
  82. solution: build box / board for uno. connect everything up. build initialization program
  83. (that will enable outputs as high)
  84. Then find a way to send commands from gnulinux. let's begin.
  85. 1. build initialization program
  86. 2. create enclosure, and wire up leds
  87. 3. run program live from gnuLinux.
  88. \end{verbatim}
  89. \end{document}