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.

552 lines
30 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. \usepackage{listings}
  8. \lstset{language=C,
  9. basicstyle=\small}
  10. \lstset{
  11. frame=tb, % draw a frame at the top and bottom of the code block
  12. tabsize=4, % tab space width
  13. showstringspaces=false, % don't mark spaces in strings
  14. numbers=left, % display line numbers on the left
  15. commentstyle=\color{green!60!blue!70}, % comment color
  16. keywordstyle=\color{red!20!blue!100}, % keyword color
  17. stringstyle=\color{red} % string color
  18. }
  19. \geometry{papersize={6in,9in},total={4.5in,6.8in}}
  20. %\title{\textbf{Door Alarm}}
  21. \author{Steak Electronics}
  22. \date{}
  23. \begin{document}
  24. %\maketitle
  25. \tableofcontents
  26. \textcolor{green!60!blue!70}{
  27. \section{Attiny Solar Energy Harvest Tests}}
  28. I have the following:
  29. \begin{itemize}
  30. \item Solar panels
  31. \item Attiny 10
  32. \end{itemize}
  33. To this list, I will add a supercap, and maybe an energy harvesting IC. The goal being to load the super cap during the day, and to run 24/7. I will need an exceptionally low power micro. The super cap will need to be about 3.3V or 5V.
  34. \textcolor{green!60!blue!70}{
  35. \subsection{Micro Considerations}}
  36. The Arduino Atmega328P is not an option. I'm looking to have a current draw of only 1mA max, (ideally 500uA) when active. Moteino is also not an option for this. Those are made for batteries. I want to be battery free \footnote{I might backtrack on this, but I think I'll do one with and one without batteries.}. A super cap, however can be used to store energy. I'll get to that shortly.
  37. For micros, I have some Attiny10 on hand, and these have a reasonably low power pull in active mode. Let's build those up first. What will the micro do? Not sure yet.
  38. \textcolor{green!60!blue!70}{
  39. \subsubsection{Micro Notes}}
  40. Must run at 1.8V / 1MHz per front page of data sheet, for 200uA draw in active mode.
  41. \\
  42. \\
  43. \textcolor{green!60!blue!70}{
  44. \subsubsection{Energy Storage}}
  45. I don't want a battery. Let's go with a super cap. The solar panels will only be active some of the time, so I will want to harvest energy with some kind of IC into the cap when the sun is out.\footnote{Reference: www.analog.com/media/en/technical-documentation/technical-articles/solarenergyharvesting.pdf is a start. I'll need to do more research.}
  46. \textcolor{green!60!blue!70}{ \subsubsection{Make parts, not scrap}} I want to make sure that all parts I build are perf board parts, not
  47. breadboard scrap (to be torn down and rebuilt again). This is an Attiny, so no need to test much, yet. Breadboards never really worked for me, so far. Too much build up, then tear down... I like things that are built to last. Parts, not scrap.
  48. \textcolor{green!60!blue!70}{
  49. \subsection{Programming}}
  50. To program the Attiny10, I'll use the Arduino adapter from the Junk + Arduino blog. I built it up\footnote{Had slight error where the Arduino + board wouldn't read - pins too short on headers, then the arduino wouldn't boot - due to bad connection on perf board shield. Thankfully, the USB port didn't try to run. Protection circuitry cut in on the laptop. This was all on a perf board. My proto pcb doesn't have this issue.}, and was able to read the memory. In order to upload to the board, you will need a compiler setup. You can possibly do it in AVRGCC, but instead I opted for either Arduino IDE (via Attiny10Core which didn't work), and then went to Mplab. In order for mplab 5.25 to work, it will need XC8 compiler, and there is a pack that can be downloaded through the IDE to get Attiny10 support. After that you can get .hex files to upload.
  51. It appears the AVR Dragon (which I have) can not be used. However, other programmers can be used. Pickit 4, Mkavrii, stk600, I think.
  52. \textcolor{green!60!blue!70}{ \subsubsection{Testing Arduino Loader}}
  53. Tested this with the blink\_LED.c in code folder. The code is as simple as possible.
  54. It is the following:
  55. \begin{lstlisting}
  56. //#include <xc.h>
  57. #include <avr/io.h>
  58. #include <util/delay.h>
  59. int main(void)
  60. {
  61. // PB2 output
  62. DDRB = 1<<2;
  63. while(1)
  64. {
  65. // Toggle PB2
  66. PINB = 1<<2;
  67. _delay_ms(500);
  68. }
  69. }
  70. \end{lstlisting}
  71. \footnote{As a recap, this code is setting the 2nd bit of DDRB register high (1), and also the PINB register, bit 2. From this we get blinky, aka a square wave.}
  72. When programmed in Mplab, with XC8 compiler, and Attiny10 support, I get the following
  73. hex output:
  74. \begin{verbatim}
  75. :100000000AC020C01FC01EC01DC01CC01BC01AC01B
  76. :1000100019C018C017C011271FBFCFE5D0E0DEBF41
  77. :0A002000CDBF03D000C0F894FFCF5D
  78. :10002A0044E041B940B95FE966E871E05150604087
  79. :0A003A007040E1F700C00000F5CFB0
  80. :02004400DDCF0E
  81. :00000001FF
  82. \end{verbatim}
  83. The content of this hex isn't the focus of this passage. Instead, I want you to review the
  84. results of a D for Dump Memory, by the Arduino Loader.
  85. \begin{verbatim}
  86. Current memory state:
  87. registers, SRAM
  88. +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
  89. 0000: 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  90. 0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  91. 0020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  92. 0030: 00 00 00 00 00 00 03 00 00 79 00 03 00 00 00 00
  93. 0040: B7 AD AE FA 58 70 63 6B FB 5A B4 1B FF FF 35 3F
  94. 0050: 67 D7 33 43 DF 5F FB 72 C9 7D FE E9 9D C5 00 12
  95. NVM lock
  96. +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
  97. 3F00: FF FF
  98. configuration
  99. +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
  100. 3F40: FF FF
  101. calibration
  102. +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
  103. 3F80: 79 FF
  104. device ID
  105. +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
  106. 3FC0: 1E 90 03 FF
  107. program
  108. +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
  109. 4000: 0A C0 20 C0 1F C0 1E C0 1D C0 1C C0 1B C0 1A C0
  110. 4010: 19 C0 18 C0 17 C0 11 27 1F BF CF E5 D0 E0 DE BF
  111. 4020: CD BF 03 D0 00 C0 F8 94 FF CF 44 E0 41 B9 40 B9
  112. 4030: 5F E9 66 E8 71 E0 51 50 60 40 70 40 E1 F7 00 C0
  113. 4040: 00 00 F5 CF DD CF FF FF FF FF FF FF FF FF FF FF
  114. 4050: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
  115. 4060: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
  116. (...some memory omitted here for brevity...)
  117. 43E0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
  118. 43F0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
  119. \end{verbatim}
  120. Notice that the "AC020C01F" is set. That is from the hex. But the 01000...
  121. before it seems to be missing. Some deciphering of how the Arduino programs
  122. the Attiny is in order here. It also doesn't end the same.
  123. Regardless, when programming, the Arduino reports 70 bytes written, and in the Mplab project memorymap.xml file, it notes 70 bytes
  124. for the sketch. This lines up.\footnote{Although for an unknown reason, every command registers twice on the Arduino serial monitor, but this appears to be harmless.}
  125. The blinking LED works. Let's move on.
  126. \textcolor{green!60!blue!70}{\subsubsection{Conclusion on Arduino Programming Attiny10}}
  127. It's possible, but you have to make a dedicated jig (almost), so it might be easier to use the official programming tools. However, based on this https://www.avrfreaks.net/forum/pickit-4-and-avr-mcu I might not have a choice. So I will use the Arduino for now. But will have to devise what on board parts are req'd for programming, and incorporate into proto board layout. \textbf{NOTE: This was before I build the proto pcb.}
  128. \textcolor{green!60!blue!70}{ \subsubsection{IO Port Switching Speed}}
  129. Using the above code without any delay\_ms, I get the following results from a default clock
  130. speed, and a 128KHz clock speed. This test was done to confirm that I could change the clock with
  131. \begin{lstlisting}
  132. //Write CCP
  133. CCP = 0xD8;
  134. //change CLK to 128KHz
  135. CLKMSR = 0b01;
  136. \end{lstlisting}
  137. There was no issue.
  138. \begin{verbatim}
  139. Default CLK (8MHz? or 1MHz?): 160KHz square wave
  140. 128KHz CLK: 2.5KHz square wave on GPIO
  141. \end{verbatim}
  142. I am going to pursue 128KHz for starters, for lower current dissipation. Note that with the Arduino loader, it is cumbersome to test and change code as you move along. It is
  143. therefore going to be necessary to use a programmer, with a dedicated header on board. \textbf{NOTE: this was before the proto board, which made programming slightly faster. Still not 100\%, but usable in terms of agility.}
  144. \textcolor{green!60!blue!70}{ \subsubsection{VCC 1.8V}}
  145. The lowest power supported: 1.8V can be applied, without any configuration
  146. needed. It does not affect IO switching speed (although obviously amplitude is affected).
  147. \begin{verbatim}
  148. 128KHz CLK (5.0V): 2.5256 KHz IO switch
  149. 128KHz CLK (3.3V): 2.5477 KHz IO switch
  150. 128KHz CLK (1.8V): 2.5849 KHz IO switch
  151. \end{verbatim}
  152. As voltage drops, IO speed increases.
  153. \\
  154. \\
  155. \textbf{VCC Dropout voltage:}
  156. \\
  157. From 1.5, it drops out at 1.248V or so. Comes back at about 1.34V
  158. \\
  159. \\
  160. Test size of 1.
  161. \\
  162. \\
  163. Can't run this with one (AA) battery, but you could with 2.
  164. \\
  165. \\
  166. Current Draw: 128KHz - IO test, 1.8V, 0.08mA (~78uA) (tested w/ HP 3478A)
  167. \\
  168. \\
  169. \textcolor{green!60!blue!70}{\subsection{Application}}
  170. First, I need a board for these and a programmer, to quickly program. Second, I need an application. I want extremely low power. Hopefully, solar with no batteries, to start. This is extremely low - that is the point. Let's keep this ridiculous.
  171. Given the power requirements put me under 1mA (with my current panels), I'm considering the following: EEPROMs would require SPI protocol. Doable, but overcomplicated for now.
  172. \\
  173. \\
  174. Eink (need to find a small and cheap enough option. So far, they have either too many pins, and/or use too much current. Something like what stores use to display prices would work, but that doesn't get the data out, only makes it readable.),
  175. \\
  176. \\
  177. Third option would be RF. That is a viable path, but not today. Let's skip that for now.
  178. \\
  179. \\
  180. Fourth option that comes to mind is IR. IR diodes, as in TV remotes, would work well here. I am choosing this as the first project. I will have dumb clients, that consist of - Attiny / IR / Sensor powered by solar. I will have a BBB that receives the IR data, and does all intelligent data gathering. To keep things simple, the IR will be binary ADC data, or otherwise sensor numbers. No SPI, no protocol complexity. That would require space on the Attiny.
  181. \\
  182. \\
  183. Let's build some boards based on the above.
  184. \\
  185. \\
  186. For sensors:
  187. While building, I came across an option. Hall effect sensors. I think also capacitive sensors can be used. This may find a use in a gate sensor, for when a driveway gate is opened or closed. With a small battery, it would work for years.
  188. Footprints: I had to make a footprint for this module on board package for one sensor. The solution to get footprints right? copy graphic image and make it into silkscreen on the board. Easy.
  189. The sensor I looked at was a temp and humidity sensor SHT11 (SHT10 is obsolete). It is low power enough. However, it's \$20. So not in my price range. Otherwise, it would work here. Looks like communication is a shift register, or SPI.
  190. \textcolor{green!60!blue!70}{
  191. \subsubsection{Magnetic Current Sensor}}
  192. There is this:
  193. BM14270AMUV-LB
  194. Which is low enough current here (\textless 1mA). But \$7 in qty, and req's I2C. Not today.
  195. \textcolor{green!60!blue!70}{
  196. \subsubsection{Accelerometers}}
  197. These are an option.
  198. Best pinout (for deadbug) is LIS344ALHTR (but lacks vcc down to 1.8)
  199. 2nd Best pinout with full 1.8 -3.6 vcc is ADXL337BCPZ-RL7
  200. (Keep in mind, these are low end options only)
  201. (Analog output only. keep it simple for now.)
  202. Runner up to all above, is KXTC9-2050-FR . But has worse pinout.
  203. Going with AD part. \$5 in single qty.
  204. Digital output Accelmeters are cheaper.
  205. All have tiny package sizes.
  206. Since I am grabbing 1 output only, will need to orient or choose correct output.
  207. PINOUT: When I said best pinout, I meant that you can solder this by hand or with hot air, without much difficulty, because the layout does not require all pins to be connected (hoping I don't get bit by floating pins, though). Or, the layout has PWR and GND together, which means some pins can be bridged.
  208. \begin{center}
  209. \includegraphics[scale=1]{../pics/adxl_pinout.png}
  210. \captionof{figure}{Some pinouts are easier than others. That said, this would still benefit from a custom breakout board. Bridge the V+ and GND, omit NC, RES pins and then you will want hot air and solder paste. Those looking for trouble can try magnet wire in a pinch.}
  211. \end{center}
  212. \textcolor{green!60!blue!70}{
  213. \subsubsection{Temperature Sensors}}
  214. Temperature can be boring, but why not. Let's throw one of these on: LMT84LP . Pin compatible with LM35. Supply current is maybe 8uA. Extremely low.
  215. LM84 (1.5V starts, to 5.5), LM85 (1.8V to 5.5)
  216. \textcolor{green!60!blue!70}{
  217. \subsubsection{Gas Sensors}}
  218. Lowest is 5mV as of writing on dkey. Skipping. The SHT would work, but its too expensive.
  219. \textcolor{green!60!blue!70}{
  220. \subsubsection{Supercap}}
  221. For now, trying whatever I have in my junk box, as super caps are expensive. If I had money, I'd try:
  222. FG0V155ZF
  223. \textcolor{green!60!blue!70}{
  224. \subsubsection{Hall Effect Sensors - Push Pull vs Open Drain Outputs}}
  225. \begin{verbatim}
  226. 9.1.1OutputTypeTradeoffs
  227. The push-pulloutputallowsfor the lowestsystempowerconsumption
  228. becausethereis no currentleakagepathwhenthe outputdriveshighor
  229. low. The open-drainoutputinvolvesa leakagepaththroughthe
  230. externalpullupresistorwhenthe outputdriveslow.The
  231. open-drainoutputsof multipledevicescan be tied
  232. togetherto forma logicalAND.In this setup,if any
  233. sensordriveslow, the voltageon the sharednodebecomeslow.
  234. Thiscan allowa singleGPIOto measurean arrayofsensors
  235. \end{verbatim} From DRV5032 data sheet.
  236. \textcolor{green!60!blue!70}{
  237. \subsubsection{Conclusion: Starting Sensors}}
  238. So as a recap, to start with affordable, low power sensors for my project, I have the following types:
  239. \begin{itemize}
  240. \item Temp sensor (cheapest)
  241. \item Magnetic Sensor (hall effect)
  242. \item Movement Sensor (accellerometer) (analog output) (tiny package)
  243. \item capacitive sensor (azoteq)(may only be short range)
  244. \end{itemize}
  245. Output, I have not determined yet. IR will not work, as its too high power. Unless I dedicate a battery just for the IR diode... Or make it battery powered. I'll start with batteries, but for solar panel and supercap, it will likely not be viable, unless I transmit extremely rarely. That is also an option, however.
  246. \subsubsection{Farad to mA}
  247. 1.5F supercap can supply 1.5A for 1 second. That is 0.025A for 60 seconds, or 25mA for a minute.
  248. Let's stay I use half that, so 12mA for 60 seconds is my supply. If I transmit once every other hour (when in sunlight)...\footnote{However, upon my testing, I found that the super cap is only useful while there is light. After dark, it won't hold for very long. Perhaps 1 hour.}
  249. \begin{center}
  250. \includegraphics[scale=0.25]{../pics/DSCN2984.JPG}
  251. \captionof{figure}{The silk screen pinout and instructions help.}
  252. \end{center}
  253. \subsection{PCB}
  254. I have built rev 2 of the board today. Using an Uno, user must remember to include VCC and GND. So the programming takes up all 6 pins. The 0.1'' headers were slightly close to the resistors, and the top row of VCC and GND headers are separated, so I labeled them V+2, and GND2.\footnote{Forgetting to plug in GND, and or 5v+ (for Uno), while still plugging in the TPI pins, did not break the Attiny10, in my tests.}
  255. The 0.05'' pin headers work perfect for scope probes. The extra breakout I made demonstrates this.
  256. \subsubsection{PCB Programming}
  257. By default, the Attiny10 idles around 1.5mA (5V), before programming.
  258. First thing to do, is to program it into a low power mode.
  259. In order to use low power, whilst using the Uno, I will need to add a jumper to the PCB,
  260. so that you can switch between V+2, and V+1. Three pin jumper. Outside pins are each V+, internal goes to Attiny V+. I'll need to remove the trace on gerber rev2, that goes from 4 to VCC.
  261. \subsubsection{PCB programming and use}
  262. It's not possible to leave the Arduino plugged in, while testing the Attiny10.
  263. example: Even if you power down the Uno, and use a jumper to change V+ rails,
  264. the power dissipation through the TPI pins (10,11,12,13) will cause a draw of about 545uA, and the Attiny10 will not toggle its led.
  265. Therefore, not only a power jumper is required to use the Attiny, but also
  266. a 4 or 5 pin 0.1" cable for the TPI pins, must be disconnected before using the Attiny.
  267. \footnote{In code section, mplab - tests2, the power draw of the 128KHz internal CLK with PB2 flipping at about 400us a cycle, at 3V VCC is about 115uA. At 2V it is ~95uA.}
  268. \subsubsection{PCB Rev3}
  269. \begin{itemize}
  270. \item Added jumper to switch between different power rails, so that
  271. Arduino can be left sort of plugged in (turns out, it is still required to disconnect 9,10,11,12,13 pins, so use a 4/5 pin cable). This makes testing low power (2-3V) code, easier, while still programming with the 5V Uno.
  272. \item Added SOT23-6 breakout
  273. \item Moved Resistors further from 9,10,11,12,13 pins.
  274. \item Added separate board for analog Accelerometer.
  275. \item Moved VCC breakout (0.5'' header pins) to connect directly to tiny, not to bottom Voltage rail.
  276. \item Added note about VCC and GND must be connected when programming.
  277. \item Added accelerometer pcb breakout. Package is small, but thanks to pinout/unused pins - is reasonable to solder with hot air. I knew this when I chose it... Then I forgot it earlier today.
  278. \end{itemize}
  279. \subsubsection{RF Comms}
  280. I want to use RF to communicate with this device. The IR would work, but would require batteries. If I'm going to use batteries I may as well use RF. Ideally, RF without batteries would be nice.
  281. I searched for LoRa modules, and came across this
  282. \\
  283. https://www.disk91.com/2015/technology/
  284. networks/first-step-in-lora-land-microchip-rn2483-test/
  285. I've added the datasheets. The RN2483 can be set with a UART, which means two pins on the Attiny. I will want to use a transistor to turn off the module (not using sleep mode), when not in use, so that's another pin. The 4th pin would be for whatever sensor I'm using. Right now, I'm thinking an accelerometer to watch for motion on a door or gate. I may need more pins, as I'd like to be able to switch the accel ic on and off as well.
  286. There is the Attiny40, and also an Attiny402. Different, but both worth considering. The Attiny40 is covered by my programmer, the 402 is not. 40 is from early 2010's, the 202/402 is from 2017. Also the Attiny20, which is less pins than the 40. But covered by my programmer. I would lean towards the 10 or the 20. 40 is too much IO.
  287. Attiny10 has I2C on board (TWI). I'm going to stick with the 10. Keep it simple.
  288. \subsubsection{Present Questions}
  289. Questions:
  290. is a two pin UART the best I can expect to find for simple rf comms
  291. is lora a reasonable solution here? I want as low power as possible,
  292. Lora is not the lowest but if I transmit rarely, and for a short time perhaps it won't matter.
  293. Is there some other way to transmit data? I don't want to use ultrasonic waves, and IR seems to be too much current, as well
  294. as requiring line of sight / lens.
  295. \subsubsection{Plan of attack}
  296. I'm going to prototype with the Microchip RF modules for now, and see if I can get this working off a solar panel. I have an ADC, and with RESET disabled another IO. Goal is now:
  297. Configure RF modules w/arduino.
  298. Configure RF module (one Uno receiver, other tiny transmitter)
  299. Attach any sensor that uses ADC. (temp sensor, resistor light or thermocouple, current sensor (monitoring power supply), and I have the ones I already tested today (but will hold off on - the accelerometer, and hall effect).
  300. Desired applications
  301. - Temp of hot surface (boiler) monitoring
  302. - Solar current input monitoring.
  303. As I've already worked with a current sense before in my battery project (Electronics\_Projects\_2019), I will use again the INA169. It seems to be low enough power for my needs, though I will double check in practice. The data sheet lacks obvious power dissipation figures, while sensing, though quiescient is about 50uA.
  304. \subsubsection{Other Sensors}
  305. I need to verify that the following sensors could be used with low power:
  306. Light dependent Resistor / Diode
  307. Sound sensor (mic)
  308. \subsubsection{RF Searching}
  309. RF Transceiver ICs require assembly/programming/time, so we want RF Transceiver modules instead. There are a number of roughly 10mA TX active, but that is the lowest I can find. Among these ics (not modules), most are SPI, have their own ARM core... The modules are a bit better in having some that can be controlled by serial. I like the TRM-433-LT, but I will skip this for now (\$20 each).
  310. I also like the RC11xx-RC232, though the latter is about 30mA TX. That may be the best I can hope for. These two are 433MHz (ISM is 433 - 434MHz). The radiocrafts product is essentially a simplified solution, preprogrammed with a uart which can be used to adjust settings. This option appears to be on part with the microchip offering I've looked at, the RN2483, in fact they both came up on my search results, next to each other. RN doesn't have what IC they use but RC, uses CC1110.
  311. Another option:
  312. ZETAPLUS-433-SO is faster than others (500Kbs), and has lower TX (18mA). Up to 2KM range...
  313. There's more options (over \$18), but for the following specifications, the above three are basically what you can choose from. Ignoring those with high TX power rates (sparkfun), or requires SPI (stmicro)
  314. Specs:
  315. \begin{itemize}
  316. \item In stock
  317. \item Frequency 433-434MHz
  318. \item battery powered vcc range (2)
  319. \end{itemize}
  320. \footnote{There's only 25.}
  321. I will start with two Radiocraft modules. Let's see how that plays out.\footnote{A set of Dev boards for the radiocraft are \$250. Ouch.}
  322. \includegraphics[scale=0.30]{../pics/DSCN0132.JPG}
  323. \captionof{figure}{RF Transmitter w/ PCB Rev 4}
  324. \subsubsection{PCB Rev 5}
  325. \begin{itemize}
  326. \item Added instructions to back of board to speed up getting back to this project after some time.
  327. \item Moved resistors to be further away from programming header
  328. \item Fixed missed connection from JMP to V1 / V2 when I moved barrel plug, and added back the bottom right mounting hole in rev4.
  329. \item Changed prg/jmp/vcc to v1/jmp/v2 (either v rail can be used for programming)
  330. \end{itemize}
  331. \subsubsection{Input Protection on Accidental Reverse Cable Hookup}
  332. I'm going to want something to block plugging in the dupont cable backwards from breaking things. I had a square wave outputting on one pin of the Attiny10, and programming was going well, with the cable left in, until I removed, then connected it in backwards. The square wave blew something on the Atmega328p of the uno. This led me to quick replacement of the Uno atmega's here: electronics\_projects\_2020/AVRdragon\_Optiboot\_Atmega328
  333. I don't know what's better. Make it foolproof, or let people learn the hard way. With the latter, they at least get a way to reprogram blank Atmegas (quite useful with Unos).
  334. Perhaps instead, a mated connector would be enough on the breakout...
  335. \subsubsection{Nuts \& Volts 433MHz RF Transmitters}
  336. A recent nuts and volts issue (2019), covered a few sections on RF in one magazine. They covered, transmitters, as well as measuring power output of a transmitter (in separate articles). The RF transmitters they covered were 433MHz, ebay transmitters. The transmitters output the square wave you feed to them. Extremely basic. But also open to modifications and adaptations. The part count is very low, with minimal ICs. (The receivers do have an IC, though.)
  337. I've bought some of these, and will do some testing. One benefit (or drawback) of these, is that they output whatever you feed them. They don't require UART.
  338. \begin{center}
  339. \includegraphics[scale=1.5]{../pics/rxtx_433.jpg}
  340. \captionof{figure}{simple rx tx on 433mhz}
  341. \end{center}
  342. \subsection{Connecting to Programmer Tips}
  343. When connecting, have a base setup that works as a sanity check. Then work on a second setup.
  344. \\
  345. It may be possible to blow out atmega328p pins if you leave attiny running, then plug in the cable back to front (i.e. pin 13 in 9).
  346. \\
  347. Make sure the cable is connected well. Loose cables, will cause the programmer to fail. Solder wires to Uno if necessary.
  348. \subsection{Attiny10 Timer Fail}
  349. \textbf{Note: this is a segway, where I tried to get a 6KHz clock out of one of the Attinys for the 60Hz project).}
  350. \\
  351. \\
  352. The goal was to get a 6KHz square wave out of the Attiny10 (first using the timer). After a night of trying to wrangle with timer 0 and CTC mode of the Attiny10 timer (which failed to work as expected). I've decided to buy a 6KHz oscillator. I was able to get 60.3KHz out of the Attiny using no optimization in mplab and IO as fast as possible. I was able to get 6.13Khz using optimization and a for loop (unfortunately the nops got optimized out).
  353. I learned that the cable I was using to program the attiny10 was giving me connection trouble. I soldered one side to an uno. That out of the way, When programming the attiny10 with my protoboard, it's as easy as, 1) connect cable to protoboard, 2) press P in serial monitor of Uno, 3) paste hex contents of mplab build into serial monitor. No need to ever reset the uno, even if it doesn't print that it detects the attiny. It's pretty good about this, and if connected correctly, will just write to the chip, when P is pressed. Then disconnect the cable, and the sketch will run. When it's time to reprogram, reconnect the cable, hit P, and paste contents, etc...
  354. \textbf{End Segway.}
  355. \subsubsection{AVR-objdump -S}
  356. Here's some code from lowpower\_tx433mhz\_2/3:
  357. \lstset{language=[x86masm]Assembler,
  358. basicstyle=\tiny}
  359. \begin{lstlisting}
  360. PORTB = bitRead(*strctPtr, i) << 2;
  361. 8c: 40 a1 lds r20, 0x40 ; 0x800040 <__DATA_REGION_ORIGIN__>
  362. 8e: 51 a1 lds r21, 0x41 ; 0x800041 <__DATA_REGION_ORIGIN__+0x1>
  363. 90: 62 a1 lds r22, 0x42 ; 0x800042 <__DATA_REGION_ORIGIN__+0x2>
  364. 92: 73 a1 lds r23, 0x43 ; 0x800043 <__DATA_REGION_ORIGIN__+0x3>
  365. 94: 08 2f mov r16, r24
  366. 96: 04 c0 rjmp .+8 ; 0xa0 <main+0x38>
  367. 98: 76 95 lsr r23
  368. 9a: 67 95 ror r22
  369. 9c: 57 95 ror r21
  370. 9e: 47 95 ror r20
  371. a0: 0a 95 dec r16
  372. a2: d2 f7 brpl .-12 ; 0x98 <main+0x30>
  373. a4: 41 70 andi r20, 0x01 ; 1
  374. a6: 44 0f add r20, r20
  375. a8: 44 0f add r20, r20
  376. aa: 42 b9 out 0x02, r20 ; 2
  377. #else
  378. //round up by default
  379. __ticks_dc = (uint32_t)(ceil(fabs(__tmp)));
  380. #endif
  381. __builtin_avr_delay_cycles(__ticks_dc);
  382. ac: 43 e0 ldi r20, 0x03 ; 3
  383. ae: 4a 95 dec r20
  384. b0: f1 f7 brne .-4 ; 0xae <main+0x46>
  385. b2: 00 00 nop
  386. b4: 8f 5f subi r24, 0xFF ; 255
  387. b6: 9f 4f sbci r25, 0xFF ; 255
  388. uint8_t i = 0;
  389. while(1)
  390. {
  391. for(i=0;i<32;i++){
  392. b8: 80 32 cpi r24, 0x20 ; 32
  393. ba: 91 07 cpc r25, r17
  394. bc: 39 f7 brne .-50 ; 0x8c <main+0x24>
  395. be: e4 cf rjmp .-56 ; 0x88 <main+0x20>
  396. \end{lstlisting}
  397. \lstset{language=C,
  398. basicstyle=\small}
  399. It's easy to read. See at the end, are the two jumps
  400. back in the loop 0x8c (for loop), and 0x88 (while 1). See the read
  401. on PORTB, and see the delay, which was \_delay\_us(10), but expands to the avr library definition.\footnote{I've noticed that the asm output is not 1:1 with code complexity. Small code changes can cause a lot more assembler code to be generated by the compiler. The asm should be watched.}
  402. \subsection{Attiny10 w/Solar and w/433MHz TX}
  403. There was an issue with 433MHz\_1 and 2 that the output was not on time. I have a 32 bit struct, and when reading the bits, the first 10 bits slowly ramp up from say 500us to 2ms for a 1 or 0. This was resolved by putting in a delay in between reads.
  404. \begin{center}
  405. \includegraphics[scale=0.3]{../pics/DSCN0200.JPG}
  406. \captionof{figure}{With a \_delay\_ms, there is no ramping up. But, the delay had to be a minimum, otherwise some ramping did occur. It's very slow, but usable for things without a lot of data to transmit.}
  407. \end{center}
  408. Some code revision notes:
  409. 433MHz\_3: 128000 KHz, 3ms delay in between bit reads being output to PORTB >> 2 (PB2). Timing is now perfect, albeit slow.
  410. 433MHz\_4: 8Mhz: 60us delay in between bit reads. faster, but has a slight time difference. RX seems to not be working right.
  411. I have 433MHz \#4 running under a LED light w/solar panel. 1.4Volts on the Attiny and its able to transmit successfully (when the rx is right next to it on the bench). 1.3Volts and noise appears on RX. So about 1.4Volts is the lower limit... Perhaps.
  412. 433MHz\_7: I confirmed in 6 and 7 that 8MHz is not working (at least consistently). Sticking with 128KHz for now. Seems to work as long as all wires are connected. Sometimes I power cycle if something is knocked.
  413. 433MHz\_8: adding sleep in place of delay\_ms(100). Will have Watchdog
  414. power back on.
  415. \subsubsection{433MHz Module TX Max Speed}
  416. 2KHz was OK. Beyond that, the RX'd signal goes out of phase, i.e. can't keep up. 5KHz is unusable. Tested with sig gen.
  417. \subsubsection{433MHz at any bus you like}
  418. The speed issues out of the way, this transmitter outputs whatever digital you feed to it. Want a UART protocol? Tie your UART TX to the transmitter. SPI? Sure, that too. You aren't locked to using UART, as in some modules. This is a great flexibility. Need encryption? Add it to the code, and you have encryption. Essentially, this 433MHz Transmitter, replaces a wire. And that is the point of RF, sometimes.
  419. It also makes the concept simple. RF is not meant to be an end in and of itself. Sometimes, it's just meant to replace wires. Your wifi device, could technically have a WIFIOUT, which would be everything on 2.4GHz. But it should be possible to have a wired WIFI. You should be able to put a wire on that WIFIOUT to a WIFIIN receiver, and have it work. The RF is still binary. It replaces a wire.
  420. The fact that its RF, that its photons, or EMR is not important. It's just replacing a wire. Signal in, signal out. RF modulation, encryption, spread spectrum, all that is details. What matters is - signal in - signal out. Wired or wireless.
  421. And you should be able to replace a wireless connection with a wire, and have it function. These modules are limited to 2KHz apparently, but they can do this.
  422. \subsection{Further Notes}
  423. https://www.eevblog.com/forum/microcontrollers/powering-devices-via-gpio-pins/msg2720044/\#msg2720044 - Using GPIO to power devices.
  424. leonerd TODO LINK HERE (bookmarks in main mach) attiny815 with rf. notice the coiled antennas
  425. https://www.eevblog.com/forum/beginners/rf-very-low-power-comms-simple/msg3016400/\#msg3016400 - Forum post regarding this project.
  426. https://trmm.net/ATtiny10 - Programming Attiny10 with free / open source toolchain
  427. https://blog.podkalicki.com/attiny13-blinky-with-timer-compa/ - Similar example for Attiny13, adapted but did not work with Attiny10.
  428. \end{document}