File size: 101,615 Bytes
08c8a6d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 |
arduino
#arduino
Table of Contents
About
Chapter 1: Getting started with arduino
Remarks
What is Arduino?
Why Use Arduino?
Versions
Examples
Bare Minimum
Blink
First Time Setup
Setup
Upload
Serial monitor
LED - With Button control
Chapter 2: Analog Inputs
Syntax
Remarks
Examples
Print out an Analog Value
Get Voltage From Analog Pin
Chapter 3: Arduino IDE
Examples
Installing on Windows
Portable app on Windows
Installing on Fedora
Installing on Ubuntu
Installing on macOS
Chapter 4: Audio Output
Parameters
Examples
1
2
2
2
2
2
2
2
3
4
5
7
7
7
9
9
9
9
9
9
11
11
11
11
11
11
11
12
12
12
Basic Note Outputs
Chapter 5: Bluetooth Communication
Parameters
Remarks
Examples
Basic bluetooth hello world
Chapter 6: Data Storage
Examples
cardInfo
SD card datalogger
SD card file dump
SD card basic file example
Listfiles
SD card read/write
Chapter 7: Digital Inputs
Syntax
Parameters
Remarks
Examples
Pushbutton reading
Chapter 8: Digital Output
Syntax
Examples
Write to pin
Chapter 9: Functions
Remarks
Examples
Create simple function
Call a function
Chapter 10: Hardware pins
Examples
12
13
13
14
14
14
15
15
15
17
18
19
20
22
24
24
24
24
24
24
26
26
26
26
27
27
27
27
27
29
29
Arduino Uno R3
Chapter 11: How Python integrates with Arduino Uno
Syntax
Parameters
Remarks
Examples
First serial communication between Arduino and Python
Chapter 12: How to store variables in EEPROM and use them for permanent storage
Syntax
Parameters
Remarks
Examples
Store a variable in EEPROM and then retrieve it and print to screen
Chapter 13: I2C Communication
Introduction
Examples
Multiple slaves
Chapter 14: Interrupts
Syntax
Parameters
Remarks
Examples
Interrupt on Button Press
Chapter 15: Libraries
Introduction
Examples
Installing libraries with the Library Manager
Including libraries in your sketch.
Chapter 16: Liquid Crystal Library
Introduction
Syntax
29
32
32
32
32
32
32
34
34
34
34
34
34
36
36
36
36
39
39
39
39
39
39
41
41
41
41
42
44
44
44
Parameters
Examples
Basic Usage
Chapter 17: Loops
Syntax
Remarks
Examples
While
For
Do ... While
Flow Control
Chapter 18: MIDI Communication
Introduction
Examples
MIDI THRU Example
MIDI Thru with Queue
MIDI Clock Generation
MIDI Messages Defined
Chapter 19: PWM - Pulse Width Modulation
Examples
Control a DC motor through the Serial port using PWM
The basics
Bill of materials: what do you need to build this example
The build
The code
PWM with a TLC5940
Chapter 20: Random Numbers
Syntax
Parameters
Remarks
Examples
44
44
44
46
46
46
46
46
47
47
48
49
49
49
49
49
51
52
57
57
57
57
58
58
58
59
60
60
60
60
60
Generate a random number
Setting a seed
Chapter 21: Serial Communication
Syntax
Parameters
Remarks
Examples
Simple read and write
Base64 filtering for serial input data
Command Handling over Serial
Serial Communication with Python
Arduino:
Python:
Chapter 22: Servo
Introduction
Syntax
Examples
Moving the servo back and forth
Chapter 23: SPI Communication
Remarks
Chip select signals
Transactions
Using the SPI in Interrupt Service Routines
Examples
Basics: initialize the SPI and a chip select pin, and perform a 1-byte transfer
Chapter 24: Time Management
Syntax
Remarks
Blocking vs. non-blocking code
Implementation details
Examples
60
61
62
62
62
62
63
63
63
63
64
64
65
66
66
66
66
66
67
67
67
67
68
68
68
70
70
70
70
70
71
blocking blinky with delay()
Non-blocking blinky with the elapsedMillis library (and class)
Non-blocking blinky with millis()
Measure how long something took, using elapsedMillis and elapsedMicros
More than 1 task without delay()
Chapter 25: Using Arduino with Atmel Studio 7
Remarks
Setup
Connections
Debugging considerations
Software setup
To include libraries in your sketch
To add the terminal window
Benefits
Examples
Atmel Studio 7 imported sketch example
Chapter 26: Variables and Data Types
Examples
Create variable
Assign value to a variable
Variable types
Credits
71
71
72
73
73
75
75
75
75
77
79
80
80
80
81
81
82
82
82
82
82
84
About
You can share this PDF with anyone you feel could benefit from it, downloaded the latest version
from: arduino
It is an unofficial and free arduino ebook created for educational purposes. All the content is
extracted from Stack Overflow Documentation, which is written by many hardworking individuals at
Stack Overflow. It is neither affiliated with Stack Overflow nor official arduino.
The content is released under Creative Commons BY-SA, and the list of contributors to each
chapter are provided in the credits section at the end of this book. Images may be copyright of
their respective owners unless otherwise specified. All trademarks and registered trademarks are
the property of their respective company owners.
Use the content presented in this book at your own risk; it is not guaranteed to be correct nor
accurate, please send your feedback and corrections to info@zzzprojects.com
https://riptutorial.com/
1
Chapter 1: Getting started with arduino
Remarks
What is Arduino?
Arduino is an open-source electronics platform based on easy-to-use hardware and software.
Why Use Arduino?
•
•
•
•
Inexpensive. You can also buy clones that are even cheaper.
Easy to use and get started with
Huge community
Completely Open Source
Versions
Version Release Date
1.0.0
2016-05-08
Examples
Bare Minimum
Here's the 'bare minimum' Arduino sketch. This can be loaded into the Arduino IDE by choosing
File > Examples > 01. Basics > Bare Minimum.
void setup() {
// put your setup code here, to run once
}
void loop() {
// put your main code here, to run repeatedly
}
Code in the setup() function will be run once when the program starts. This is useful to set up I/O
pins, initialize variables, etc. Code in the loop() function will be run repeatedly until the Arduino is
switched off or a new program is uploaded. Effectively, the code above looks like this inside the
Arduino runtime library:
setup();
while(1) {
https://riptutorial.com/
2
loop();
}
Unlike programs running on your computer, Arduino code can never quit. This is because the
microcontroller only has one program loaded into it. If this program quit there would be nothing to
tell the microcontroller what to do.
Blink
Here's a short example that demonstrates the setup() and loop() functions. This can be loaded
into the Arduino IDE by choosing File > Examples > 01. Basics > Blink. (Note: Most Arduino
boards have an LED already connected to pin 13, but you may need to add an external LED to
see the effects of this sketch.)
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
The above snippet:
1.
Defines the setup() function. The setup() function gets called first on execution in every
Arduino program.
1.
Sets pin 13 as an output.
Without this, it might be set to an input, which would make the LED not work; however
once it is set as an output it will stay that way so this only needs to be done once when
the program starts.
2.
Defines the loop() function. The loop() function is called repeatedly for as long as the
program is running.
1.
2.
3.
4.
digitalWrite(13, HIGH); turns the LED on.
delay(1000); waits one second (1000 milliseconds).
digitalWrite(13, LOW); turns the LED off.
delay(1000); waits one second (1000 milliseconds).
Because loop() is run repeatedly for as long as the program is running, the LED will flash on and
off with a period of 2 seconds (1 second on, 1 second off). This example is based off of the
Arduino Uno and any other board that already has an LED connected to Pin 13. If the board that is
being used does not have an on-board LED connected to that pin, one can be attached externally.
https://riptutorial.com/
3
More on timing (for example delays and measuring time): Time Management
First Time Setup
Software needed: Arduino IDE
https://riptutorial.com/
4
https://riptutorial.com/
Setup
5
Most Arduino-compatible boards have a USB port and come with a USB cable. Plug in the Arduino
Arduino IDE will start with a new sketch, typically with an emtpy setup() and loop()
functions. This is enough to upload to an Arduino board, but it will do nothing at all. The "Blink"
example sketch works as a simple test when first using an Arduino board. Go to File → Examples
→ 01.Basics → Blink. This will open a new window with the Blink sketch.
Select your board. Go to Tools → Board → [name of your Arduino board].
Select the COM port for your board. Most Aurduino-compatible boards will create a fake COM
port, which is used for serial communication (debugging) and for programming the board. COM 1
https://riptutorial.com/
6
is usually already present, and your board will create a new one, e.g. COM 4. Select this from
Tools → Port → COM 4 (or other COM number).
Some boards have additional settings in the Tools menu, such as clock speed. These vary from
board to board, but usually an acceptable set of defaults is already selected.
Upload
You are now ready to upload Blink. Click the Upload button or select Sketch → Upload. The
sketch will compile, then upload to your Arduino board. If everything worked, the on-board LED will
start blinking on and off every second.
Serial monitor
In the Arduino IDE ypu hava a serial monitor. To open it use the button serial monitor at the right
side of the window.
Be sure that the code is uploaded before you open the monitor. The upload and monitor will not
run at the same time!
LED - With Button control
You can also use this code to setup an LED with a button switch with a pull up resistor, this could
preferably be with the next step after setting up the intial LED controller
int buttonState = 0; // variable for reading the pushbutton status
void setup()
{
// initialize the LED pin as an output:
pinMode(13, OUTPUT); // You can set it just using its number
// initialize the pushbutton pin as an input:
pinMode(2, INPUT);
}
void loop()
{
// read the state of the pushbutton value:
buttonState = DigitalRead(2);
// check if the pushbutton is pressed.
// If it's not, the buttonState is HIGH : if (buttonState == HIGH)
{
// turn LED off:
https://riptutorial.com/
7
digitalWrite(13, LOW);
}
else
{
// turn LED off:
digitalWrite(13, HIGH);
}
}
Read Getting started with arduino online: https://riptutorial.com/arduino/topic/610/getting-started-
with-arduino
https://riptutorial.com/
8
Chapter 2: Analog Inputs
Syntax
•
analogRead(pin) //Read from the given pin.
Remarks
Serial.println(val)
For help with Serial communication, see: Serial Communication
Examples
Print out an Analog Value
int val = 0; // variable used to store the value
// coming from the sensor
void setup() {
Serial.begin(9600); //Begin serializer to print out value
// Note: Analogue pins are
// automatically set as inputs
}
void loop() {
val = analogRead(0); // read the value from
// the sensor connected to A0.
Serial.println(val); //Prints the value coming in from the analog sensor
delay(10); // stop the program for
// some time
}
Get Voltage From Analog Pin
Analog pins can be used to read voltages which is useful for battery monitoring or interfacing with
analog devices. By default the AREF pin will be the same as the operating voltage of the arduino,
but can be set to other values externally. If the voltage to read is larger than the input voltage, a
potential devider will be needed to lower the analog voltage.
#define analogPin 14 //A0 (uno)
#define AREFValue 5 //Standard for 5V Arduinos
#define ADCResolution 1023 //Standard for a 10bit ADC
int ADCValue = 0;
https://riptutorial.com/
9
float voltage = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
readADC();
Serial.print(voltage); Serial.println("V");
}
void readADC()
{
ADCValue = analogRead(analogPin);
float = ( ( (float)ADCValue/ADCRange ) * AREFValue ); //Convert the ADC value to a
float, devide by the ADC resolution and multiply by the AREF voltage
}
Read Analog Inputs online: https://riptutorial.com/arduino/topic/2382/analog-inputs
https://riptutorial.com/
10
Chapter 3: Arduino IDE
Examples
Installing on Windows
1.
2.
3.
Go to https://www.arduino.cc/en/Main/Software
Click the "Windows Installer" link
Follow the instructions
Portable app on Windows
To use the Arduino IDE on Windows without needing to install it:
1.
2.
3.
4.
Go to https://www.arduino.cc/en/Main/Software
Click the "Windows ZIP file for non admin install" link
Extract the archive to a folder
Open the folder, and double click Arduino.exe
Installing on Fedora
1.
2.
Open a terminal and run: sudo dnf install arduino
Open the Arduino application, or type arduino into the terminal
Installing on Ubuntu
1.
2.
Open a terminal and run: sudo apt-get install arduino
Open the Arduino application, or type arduino into the terminal
Installing on macOS
1.
2.
3.
4.
Go to https://www.arduino.cc/en/Main/Software
Click the Mac OS X link.
Unzip the .zipfile.
Move the Arduino application to Applications.
Read Arduino IDE online: https://riptutorial.com/arduino/topic/3790/arduino-ide
https://riptutorial.com/
11
Chapter 4: Audio Output
Parameters
Parameter Details
speaker
Should be an output to an analog speaker
Examples
Basic Note Outputs
#define NOTE_C4 262 //From pitches.h file defined in [Arduino Tone Tutorial][1]
int Key = 2;
int KeyVal = 0;
byte speaker = 12;
void setup()
{
pinMode(Key, INPUT); //Declare our key (button) as input
pinMode(speaker, OUTPUT);
}
void loop()
{
KeyVal = digitalRead(Key);
if (KeyVal == HIGH) {
tone(speaker, NOTE_C4); //Sends middle C tone out through analog speaker
} else {
noTone(speaker); //Ceases tone emitting from analog speaker
}
delay(100);
}
[1]: https://www.arduino.cc/en/Tutorial/toneMelody
Read Audio Output online: https://riptutorial.com/arduino/topic/2384/audio-output
https://riptutorial.com/
12
Chapter 5: Bluetooth Communication
Parameters
method
details
SoftwareSerial.h
Documentation
SoftwareSerial(rxPin,
txPin, inverse_logic)
Constructor. rxPin: Data in (receive) pin, defaults to 0. txPin:
Data out (transmit) pin, defaults to 1. inverse_logic: If true, treats
LOW as if it were HIGH and HIGH as LOW when determining bit
values. defaults to false.
begin(speed)
Sets the baud rate for serial communication. Supported baud
rates are 300, 600, 1200, 2400, 4800, 9600, 14400, 19200,
28800, 31250, 38400, 57600, and 115200.
available()
Check if there is some data over serial
read()
Reads a string from serial
isListening()
Checks to see if requested software serial port is actively
listening.
overflow()
peek()
print(data)
println(data)
listen()
Checks if a software serial buffer overflow has occurred. Calling
this function clears the overflow flag, meaning that subsequent
calls will return false unless another byte of data has been
received and discarded in the meantime. The software serial
buffer can hold 64 bytes.
Return a character that was received on the RX pin of the
software serial port. Unlike read(), however, subsequent calls to
this function will return the same character. Note that only one
SoftwareSerial instance can receive incoming data at a time
(select which one with the listen() function).
Prints data to the transmit pin of the software serial port. Works
the same as the Serial.print() function.
Prints data to the transmit pin of the software serial port, followed
by a carriage return and line feed. Works the same as the
Serial.println() function.
Enables the selected software serial port to listen. Only one
software serial port can listen at a time; data that arrives for other
ports will be discarded. Any data already received is discarded
during the call to listen() (unless the given instance is already
https://riptutorial.com/
13
method
write(data)
Remarks
details
listening).
Prints data to the transmit pin of the software serial port as raw
bytes. Works the same as the Serial.write() function.
Common Mistake : If you keep the rx and tx pins at default values (0 and 1), you cannot upload
new code until and unless you remove it, so it's almost always better to change the tx and rx pins
in the SoftwareSerial constructor.
Examples
Basic bluetooth hello world
#include <SoftwareSerial.h>
// its always better to change the default tx and rx as the may interfere with other process
in future.
// configure tx , rx by defualt they will be 0 and 1 in arduino UNO
SoftwareSerial blue(3,2);
void setup() {
// preferred baud rate/data transfer rate in general is 38400
blue.begin(38400);
// do initialization or put one time executing code here
}
void loop() {
// put code that you want it to run every time no matter what
if(blue.available()){
// put only that code which needsd to run when there is some data
// This means that the their is some data sent over the bluetooth
// You can do something with the data
int n;
// consider that the data received to be integer, read it by using blue.parseInt();
n = blue.parseInt();
}
}
Read Bluetooth Communication online: https://riptutorial.com/arduino/topic/2543/bluetooth-
communication
https://riptutorial.com/
14
Chapter 6: Data Storage
Examples
cardInfo
/*
SD card test
This example shows how use the utility libraries on which the'
SD library is based in order to get info about your SD card.
Very useful for testing a card when you're not sure whether its working or not.
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
** CS - depends on your SD card shield or module.
Pin 4 used here for consistency with other Arduino examples
created 28 Mar 2011
by Limor Fried
modified 9 Apr 2012
by Tom Igoe
*/
// include the SD library:
#include <SPI.h>
#include <SD.h>
// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 4;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("\nInitializing SD card...");
// we'll use the initialization code from the utility libraries
// since we're just testing if the card is working!
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card inserted?");
https://riptutorial.com/
15
Serial.println("* is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
return;
} else {
Serial.println("Wiring is correct and a card is present.");
}
// print the type of card
Serial.print("\nCard type: ");
switch (card.type()) {
case SD_CARD_TYPE_SD1:
Serial.println("SD1");
break;
case SD_CARD_TYPE_SD2:
Serial.println("SD2");
break;
case SD_CARD_TYPE_SDHC:
Serial.println("SDHC");
break;
default:
Serial.println("Unknown");
}
// Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
if (!volume.init(card)) {
Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the
card");
return;
}
// print the type and size of the first FAT-type volume
uint32_t volumesize;
Serial.print("\nVolume type is FAT");
Serial.println(volume.fatType(), DEC);
Serial.println();
volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
volumesize *= volume.clusterCount(); // we'll have a lot of clusters
volumesize *= 512; // SD card blocks are always 512 bytes
Serial.print("Volume size (bytes): ");
Serial.println(volumesize);
Serial.print("Volume size (Kbytes): ");
volumesize /= 1024;
Serial.println(volumesize);
Serial.print("Volume size (Mbytes): ");
volumesize /= 1024;
Serial.println(volumesize);
Serial.println("\nFiles found on the card (name, date and size in bytes): ");
root.openRoot(volume);
// list all files in the card with date and size
root.ls(LS_R | LS_DATE | LS_SIZE);
}
void loop(void) {
}
https://riptutorial.com/
16
SD card datalogger
/*
SD card datalogger
This example shows how to log data from three analog sensors
to an SD card using the SD library.
The circuit:
* analog sensors on analog ins 0, 1, and 2
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4
created 24 Nov 2010
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>
const int chipSelect = 4;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
}
void loop()
{
// make a string for assembling the data to log:
String dataString = "";
// read three sensors and append to the string:
for (int analogPin = 0; analogPin < 3; analogPin++) {
int sensor = analogRead(analogPin);
dataString += String(sensor);
if (analogPin < 2) {
dataString += ",";
}
https://riptutorial.com/
17
}
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
}
SD card file dump
/*
SD card file dump
This example shows how to read a file from the SD card using the
SD library and send it over the serial port.
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4
created 22 December 2010
by Limor Fried
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>
const int chipSelect = 4;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("Initializing SD card...");
https://riptutorial.com/
18
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("datalog.txt");
// if the file is available, write to it:
if (dataFile) {
while (dataFile.available()) {
Serial.write(dataFile.read());
}
dataFile.close();
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
}
void loop()
{
}
SD card basic file example
/*
SD card basic file example
This example shows how to create and destroy an SD card file
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4
created Nov 2010
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>
File myFile;
void setup()
{
// Open serial communications and wait for port to open:
https://riptutorial.com/
19
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
if (SD.exists("example.txt")) {
Serial.println("example.txt exists.");
}
else {
Serial.println("example.txt doesn't exist.");
}
// open a new file and immediately close it:
Serial.println("Creating example.txt...");
myFile = SD.open("example.txt", FILE_WRITE);
myFile.close();
// Check to see if the file exists:
if (SD.exists("example.txt")) {
Serial.println("example.txt exists.");
}
else {
Serial.println("example.txt doesn't exist.");
}
// delete the file:
Serial.println("Removing example.txt...");
SD.remove("example.txt");
if (SD.exists("example.txt")) {
Serial.println("example.txt exists.");
}
else {
Serial.println("example.txt doesn't exist.");
}
}
void loop()
{
// nothing happens after setup finishes.
}
Listfiles
/*
Listfiles
This example shows how print out the files in a
directory on a SD card
The circuit:
https://riptutorial.com/
20
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4
created Nov 2010
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
modified 2 Feb 2014
by Scott Fitzgerald
This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>
File root;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
root = SD.open("/");
printDirectory(root, 0);
Serial.println("done!");
}
void loop()
{
// nothing happens after setup finishes.
}
void printDirectory(File dir, int numTabs) {
while(true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
break;
}
for (uint8_t i=0; i<numTabs; i++) {
Serial.print('\t');
}
Serial.print(entry.name());
https://riptutorial.com/
21
if (entry.isDirectory()) {
Serial.println("/");
printDirectory(entry, numTabs+1);
} else {
// files have sizes, directories do not
Serial.print("\t\t");
Serial.println(entry.size(), DEC);
}
entry.close();
}
}
SD card read/write
/*
SD card read/write
This example shows how to read and write data to and from an SD card file
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4
created Nov 2010
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>
File myFile;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open("test.txt", FILE_WRITE);
https://riptutorial.com/
22
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
// re-open the file for reading:
myFile = SD.open("test.txt");
if (myFile) {
Serial.println("test.txt:");
// read from the file until there's nothing else in it:
while (myFile.available()) {
Serial.write(myFile.read());
}
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
void loop()
{
// nothing happens after setup
}
Read Data Storage online: https://riptutorial.com/arduino/topic/6584/data-storage
https://riptutorial.com/
23
Chapter 7: Digital Inputs
Syntax
•
•
pinMode(pin, pinMode) // Sets the pin to the mode defined.
digitalRead(pin); // Reads the value from a specified digital pin,
Parameters
Paramter Details
pinmode
Should be set to INPUT or INPUT_PULLUP
Remarks
If the input pin is not pulled LOW or HIGH, the value will float. That is, it won't be clearly a 1 or a 0,
but somewhere in between. For digital input, a pullup or pulldown resistor is a necessity.
Examples
Pushbutton reading
This is an basic example on how to wire up and make an LED turn on/off when the pushbutton is
pressed.
/* Basic Digital Read
* ------------------
*
* turns on and off a light emitting diode(LED) connected to digital
https://riptutorial.com/
24
* pin 13, when pressing a pushbutton attached to pin 7. It illustrates the
* concept of Active-Low, which consists in connecting buttons using a
* 1K to 10K pull-up resistor.
*
* Created 1 December 2005
* copyleft 2005 DojoDave <http://www.0j0.org>
* http://arduino.berlios.de
*
*/
int ledPin = 13; // choose the pin for the LED
int inPin = 7; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inPin, INPUT); // declare pushbutton as input
}
void loop(){
val = digitalRead(inPin); // read input value
if (val == HIGH) { // check if the input is HIGH (button released)
digitalWrite(ledPin, LOW); // turn LED OFF
} else {
digitalWrite(ledPin, HIGH); // turn LED ON
}
}
Example taken from Arduino.cc.
Read Digital Inputs online: https://riptutorial.com/arduino/topic/1662/digital-inputs
https://riptutorial.com/
25
Chapter 8: Digital Output
Syntax
•
digitalWrite(pin, value)
Examples
Write to pin
int ledPin = 13; // LED connected to digital pin 13
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop()
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second
}
Example at Arduino.cc.
Read Digital Output online: https://riptutorial.com/arduino/topic/2477/digital-output
https://riptutorial.com/
26
Chapter 9: Functions
Remarks
Other than in ordinary C / C++ , the Arduino IDE allows to call a function before it is defined.
In .cpp files, you have to define the function, or at least declare the function prototype before you
can use it.
In an .ino file, the Arduino IDE creates such a prototype behind the scenes.
Arduino - function declaration - official
Examples
Create simple function
int squareNum (int a) {
return a*a;
}
int : return type
squareNum : function name
int a : parameter type and name
return a*a : return a value (same type as the return type defined at the beginning)
Call a function
If you have a function declared you can call it anywhere else in the code. Here is an example of
calling a function:
https://riptutorial.com/
27
void setup(){
Serial.begin(9600);
}
void loop() {
int i = 2;
int k = squareNum(i); // k now contains 4
Serial.println(k);
delay(500);
}
int squareNum(int a) {
return a*a;
}
Read Functions online: https://riptutorial.com/arduino/topic/2380/functions
https://riptutorial.com/
28
Chapter 10: Hardware pins
Examples
Arduino Uno R3
Microcontrollers use pins to interact with the rest of the circuit. These pins will usually be one of
input / output pins, vin or ground. I/O pins can be simple digital I/O pins, or they can have some
special carachteristics like being able to vary the voltage of their output using pulse width
modulation. Here's a schematic of the Arduino R3 Uno and its pins.
https://riptutorial.com/
29
(source)
PWM Pins
https://riptutorial.com/
30
PWM allows you to control the voltage of the output by switching the output between high and low
very very quickly. The percentage of time the pin is high is called its 'duty cycle'.
PWM Pins: 3, 5, 6, 9, 10, 11
Analog Inputs
Just like a PWM pin can put out a range of voltages, analog pins on the Arduino Uno R3 can
sense a range of oinput voltages. You might use this to read the position of a potentiometer or
another input with a smoothly variable input. Please note that analog pins can't do analogWrite
output - for this you need to use PWM pins.
Analog ADC Pins: A0, A1, A2, A3, A4, A5
Serial, SPI and I2C
The serial pins on the Arduino Uno R3 are also used by (for instance) the USB to Serial chip when
it communicates with a computer via the on board USB port. Serial: Tx on 0, Rx on 1
SPI and I2C are communication protocols the Arduino can use to talk to shields, sensors, outputs
etc...:
SPI Pins: MOSI on 11, MISO on 12, SCLK on 13, SS on 10
I2C Pins: SCL on A5, SDA on A4
On-board LED
The Arduino Uno R3 has an LED with its own resistor attached to pin 13. This means that even if
you don't attach any LEDs to your board, if you set pin 13 to an output and set it high, you should
see an LED on the board come on. Use the 'Blink' example sketch to locate your onboard LED.
From the Arduino Digital Pins Page
NOTE: Digital pin 13 is harder to use as a digital input than the other digital pins
because it has an LED and resistor attached to it that's soldered to the board on most
boards. If you enable its internal 20k pull-up resistor, it will hang at around 1.7V instead
of the expected 5V because the onboard LED and series resistor pull the voltage level
down, meaning it always returns LOW. If you must use pin 13 as a digital input, set its
pinMode() to INPUT and use an external pull down resistor.
On-board LED pin: 13
Read Hardware pins online: https://riptutorial.com/arduino/topic/4386/hardware-pins
https://riptutorial.com/
31
Chapter 11: How Python integrates with
Arduino Uno
Syntax
•
•
•
•
Serial.begin(baudrate) // Set baud rate (bits per second) for serial data transmission
Serial.println(value) // Print data to serial port followed by Carriage Return \r and
Newline character \n
serial.Serial((port=None, baudrate=9600, bytesize=EIGHTBITS, parity=PARITY_NONE,
stopbits=STOPBITS_ONE, timeout=None, xonxoff=False, rtscts=False, write_timeout=None,
dsrdtr=False, inter_byte_timeout=None) // Initialize serial port with all parameters
serial.readline() // Read serial data which contains Carriage Return \r and Newline
character \n
Parameters
Parameter Details
serial
Python package contains classes and methods to access serial port
time
Python package includes time-related functions
Remarks
I use an Arduino Uno with Arduino IDE 1.6.9 and Python 2.7.12 running in Windows 10.
Examples
First serial communication between Arduino and Python
In this very first example, a basic serial write operation is started from an Arduino device.
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Hello World!");
delay(100);
}
In setup(), function Serial.begin(9600) sets up the baud rate for serial data communication. In this
example, a baud rate of 9600 is used. Other values can be read here: Arduino Serial.begin()
function
https://riptutorial.com/
32
In loop(), the first message we would like to send is "Hello World!". This message is transmitted by
using Serial.println("Hello World!") as it will send this string to serial port in ASCII format. At the
end of the message, there are Carriage Return (CR, \r) and Newline character (\n). Also, a delay
of 100 milliseconds is used each time program prints to serial port.
Next, upload this Arduino sketch via COM port (remember this COM port number as it will be used
in Python program).
The Python program reading serial data sent from Arduino device is shown below:
import serial
import time
ser = serial.Serial('COM8', 9600)
while (1):
print ser.readline()
time.sleep(0.1)
First, pyserial package should be imported. For more information about installing pyserial in
Windows environment, please check this instruction: Installing Python and pyserial. Then, we
initialize the serial port with COM port number and baud rate. The baud rate needs to be the same
as used in Arduino sketch.
Received message will be printed in while loop using readline() function. A delay of 100
milliseconds is also used here as same as in Arduino sketch. Please notice that pyserial
readline() function requires a timeout when opening a serial port (pyserial documentation:
PySerial ReadLine).
Read How Python integrates with Arduino Uno online:
https://riptutorial.com/arduino/topic/6722/how-python-integrates-with-arduino-uno
https://riptutorial.com/
33
Chapter 12: How to store variables in
EEPROM and use them for permanent
storage
Syntax
•
•
EEPROM.write(address, value); //(Store variables in EEPROM in a particular address)
EEPROM.read(address); //(Retrieve values from EEPROM and read data stored in
EEPROM)
Parameters
Parameters of
EEPROM.write
Detail
address
The address where value is to be stored in EEPROM
value
Main variable to store in EEPROM. Note that this is a uint_8 (single
byte)—you must split multiple-byte data types into single bytes
yourself. Or you can use EEPROM.put to store floats or other data types.
Parameters of
EEPROM.Read
Detail
address
The address from which the variable is to be read
Remarks
The allowable addresses vary by hardware.
•
•
•
•
ATMega328 (Uno, Pro Mini, etc.): 0–1023
ATMega168: 0-511
ATMega1280: 0-4095
ATMega2560: 0-4095
source
Examples
Store a variable in EEPROM and then retrieve it and print to screen
First, add a reference to <EEPROM.h> at the start of your sketch:
https://riptutorial.com/
34
#include <EEPROM.h>
Then your other code:
// Stores value in a particular address in EEPROM. There are almost 512 addresses present.
// Store value 24 to Address 0 in EEPROM
int addr = 0;
int val = 24;
EEPROM.write(addr, val); // Writes 24 to address 0
// ---------
// Retrieves value from a particular address in EEPROM
// Retrieve value from address 0 in EEPROM
int retrievedVal = EEPROM.read(0); // Retrieves value stored in 0 address in
// EEPROM
// *[NOTE: put Serial.begin(9600); at void setup()]*
Serial.println(retrievedVal); // Prints value stored in EEPROM Address 0 to
// Serial (screen)
Read How to store variables in EEPROM and use them for permanent storage online:
https://riptutorial.com/arduino/topic/5987/how-to-store-variables-in-eeprom-and-use-them-for-
permanent-storage
https://riptutorial.com/
35
Chapter 13: I2C Communication
Introduction
I2C is a communication protocol that can make two or more Arduino boards talk to each other.
The protocol uses two pins - SDA (data line) and SCL (clock line). Those pins are different from
one Arduino board type to another, so check the board specification. The I2C protocol set one
Arduino board as the master, and all the others as a slave. Each slave has a different address that
the programmer set hard-coded. Remark: Make sure all boards connected to the same VCC
source
Examples
Multiple slaves
The following example shows how the master can receive data from multiple slaves. In this
example the slave sends two short numbers. The first one is for temperature, and the second one
is for moisture. Please notice that the temperature is a float (24.3). In order to use only two bytes
and not four (float is four bytes), I multiple the temperature in 10, and save it as a short. So here is
the master code:
#include <Wire.h>
#define BUFFER_SIZE 4
#define MAX_NUMBER_OF_SLAVES 24
#define FIRST_SLAVE_ADDRESS 1
#define READ_CYCLE_DELAY 1000
byte buffer[BUFFER_SIZE];
void setup()
{
Serial.begin(9600);
Serial.println("MASTER READER");
Serial.println("*************");
Wire.begin(); // Activate I2C link
}
void loop()
{
for (int slaveAddress = FIRST_SLAVE_ADDRESS;
slaveAddress <= MAX_NUMBER_OF_SLAVES;
slaveAddress++)
{
Wire.requestFrom(slaveAddress, BUFFER_SIZE); // request data from the slave
if(Wire.available() == BUFFER_SIZE)
{ // if the available data size is same as I'm expecting
// Reads the buffer the slave sent
for (int i = 0; i < BUFFER_SIZE; i++)
{
https://riptutorial.com/
36
buffer[i] = Wire.read(); // gets the data
}
// Parse the buffer
// In order to convert the incoming bytes info short, I use union
union short_tag {
byte b[2];
short val;
} short_cast;
// Parse the temperature
short_cast.b[0] = buffer[0];
short_cast.b[1] = buffer[1];
float temperature = ((float)(short_cast.val)) / 10;
// Parse the moisture
short_cast.b[0] = buffer[2];
short_cast.b[1] = buffer[3];
short moisture = short_cast.val;
// Prints the income data
Serial.print("Slave address ");
Serial.print(slaveAddress);
Serial.print(": Temprature = ");
Serial.print(temprature);
Serial.print("; Moisture = ");
Serial.println(moisture);
}
}
Serial.println("*************************");
delay(READ_CYCLE_DELAY);
}
}
And now the slave code:
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
//=====================
// This is the hard-coded address. Change it from one device to another
#define SLAVE_ADDRESS 1
//=====================
// I2C Variables
#define BUFFER_SIZE 2
#define READ_CYCLE_DELAY 1000
short data[BUFFER_SIZE];
// Temprature Variables
OneWire oneWire(8);
DallasTemperature temperatureSensors(&oneWire);
float m_temperature;
// Moisture Variables
short m_moisture;
// General Variables
https://riptutorial.com/
37
int m_timestamp;
void setup()
{
Serial.begin(9600);
Serial.println("SLAVE SENDER");
Serial.print("Node address: ");
Serial.println(SLAVE_ADDRESS);
Serial.print("Buffer size: ");
Serial.println(BUFFER_SIZE * sizeof(short));
Serial.println("***********************");
m_timestamp = millis();
Wire.begin(NODE_ADDRESS); // Activate I2C network
Wire.onRequest(requestEvent); // Set the request event handler
temperatureSensors.begin();
}
void loop()
{
if(millis() - m_timestamp < READ_CYCLE_DELAY) return;
// Reads the temperature
temperatureSensors.requestTemperatures();
m_temperature = temperatureSensors.getTempCByIndex(0);
// Reads the moisture
m_moisture = analogRead(A0);
}
void requestEvent()
{
data[0] = m_temperature * 10; // In order to use short, I multiple by 10
data[1] = m_moisture;
Wire.write((byte*)data, BUFFER_SIZE * sizeof(short));
}
Read I2C Communication online: https://riptutorial.com/arduino/topic/9092/i2c-communication
https://riptutorial.com/
38
Chapter 14: Interrupts
Syntax
•
•
•
•
•
•
•
digitalPinToInterrupt(pin); // converts a pin id to an interrupt id, for use with attachInterrupt()
and detachInterrupt().
attachInterrupt(digitalPinToInterrupt(pin), ISR, mode); // recommended
attachInterrupt(interrupt, ISR, mode); // not recommended
detachInterrupt(digitalPinToInterrupt(pin));
detachInterrupt(interrupt);
noInterrupts(); // disables interrupts
interrupts(); // re-enable interrupts after noInterrupts() has been called.
Parameters
Parameter Notes
interrupt
Id of the interrupt. Not to be mistaken for pin number.
Interrupt Service Routine. This is the method which will be executed when the
interrupt occurs.
What should cause the interrupt to trigger. One of LOW, CHANGE, RISING, or
FALLING. Due boards also allow HIGH.
ISR
mode
Remarks
Interrupt Service Routines (ISRs) should be as short as possible, since they pause main program
execution and can thus screw up time-dependent code. Generally this means in the ISR you set a
flag and exit, and in the main program loop you check the flag and do whatever that flag is
supposed to do.
You cannot use delay() or millis() in an ISR because those methods themselves rely on
interrupts.
Examples
Interrupt on Button Press
https://riptutorial.com/
39
This example uses a push button (tact switch) attached to digital pin 2 and GND, using an internal
pull-up resistor so pin 2 is HIGH when the button is not pressed.
const int LED_PIN = 13;
const int INTERRUPT_PIN = 2;
volatile bool ledState = LOW;
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(INTERRUPT_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), myISR, FALLING); // trigger when
button pressed, but not when released.
}
void loop() {
digitalWrite(LED_PIN, ledState);
}
void myISR() {
ledState = !ledState;
// note: LOW == false == 0, HIGH == true == 1, so inverting the boolean is the same as
switching between LOW and HIGH.
}
One gotcha with this simple example is that push buttons tend to bounce, meaning that when
pressing or releasing, the circuit opens and closes more than once before it settles into the final
closed or open state. This example doesn't take that into account. As a result, sometimes pressing
the button will toggle the LED multiple times, instead of the expected once.
Read Interrupts online: https://riptutorial.com/arduino/topic/2913/interrupts
https://riptutorial.com/
40
Chapter 15: Libraries
Introduction
Here you will find documentation on:
-Installing libraries into the Arduino IDE
-Including libraries into a Sketch
Examples
Installing libraries with the Library Manager
To install a new library into the Arduino IDE:
•
Open Sketch Menu > Include Library > Manage Libraries.
Once you have opened the Library Manager you can use the menu in the top to filter
the results.
•
Click on the library you want, select a version in the drop down menu, and click
install.
https://riptutorial.com/
41
Now your library is installed. In order to use it, you need to include it in your sketch.
Including libraries in your sketch.
Once you have installed a library, you need to include it in your sketch in order to use it.
•
Open the Sketch Menu > Include Library and click the Library you want to include.
https://riptutorial.com/
42
•
Now, the IDE has generated the required inclusion tags into your code.
Now the Library is included in your sketch, and you can use it in your code.
Read Libraries online: https://riptutorial.com/arduino/topic/8896/libraries
https://riptutorial.com/
43
Chapter 16: Liquid Crystal Library
Introduction
Arduino's Liquid Crystal Library is a library for controlling LCD displays compatible the Hitachi
HD44780 driver, characterised by their 16 pin interface. The 16 pins might be connected via an
I2C interface. These displays contain a matrix of 5x7 pixel blocks used to display characters or
small monochromatic images. The displays are usually named according to how many rows and
columns they have, e.g. 16x2 or 1602 for 16 columns and 2 rows, and 20x4 or 2004 for 20
columns and 4 rows.
Syntax
•
•
•
•
•
#include <LiquidCrystal.h> // Includes the library
LiquidCrystal(rs, enable, d4, d5, d6, d7) //
LiquidCrystal(rs, rw, enable, d4, d5, d6, d7)
LiquidCrystal(rs, enable, d0, d1, d2, d3, d4, d5, d6, d7)
LiquidCrystal(rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7)
Parameters
LiquidCrystal
Parameter
Details
the number of the Arduino pin that is connected to the RS pin on the LCD
the number of the Arduino pin that is connected to the RW pin on the
LCD (optional)
the number of the Arduino pin that is connected to the enable pin on the
LCD
the numbers of the Arduino pins that are connected to the corresponding
data pins on the LCD. d0, d1, d2, and d3 are optional; if omitted, the LCD
will be controlled using only the four data lines (d4, d5, d6, d7).
rs
rw
enable
d0 - d7
Examples
Basic Usage
/*
Wiring:
LCD pin 1 (VSS) -> Arduino Ground
LCD pin 2 (VDD) -> Arduino 5V
https://riptutorial.com/
44
LCD pin 3 (VO) -> Arduino Ground
LCD pin 4 (RS) -> Arduino digital pin 12
LCD pin 5 (RW) -> Arduino Ground
LCD pin 6 (E) -> Arduino digital pin 11
LCD pin 11 (D4) -> Arduino digital pin 5
LCD pin 12 (D5) -> Arduino digital pin 4
LCD pin 13 (D6) -> Arduino digital pin 3
LCD pin 14 (D7) -> Arduino digital pin 2
*/
#include <LiquidCrystal.h> // include the library
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// start writing on the first row and first column.
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("hello, world!");
}
void loop() {
// No need to do anything to keep the text on the display
}
Read Liquid Crystal Library online: https://riptutorial.com/arduino/topic/9395/liquid-crystal-library
https://riptutorial.com/
45
Chapter 17: Loops
Syntax
•
•
•
for (declaration, condition, iteration) { }
while (condition) { }
do { } while (condition)
Remarks
General Remark If you intend to create a loop to wait for something to happen, you're probably on
the wrong track here. Rather remember that all code after setup() is run from a method called
loop(). So if you need to wait for something, it's easiest to not do anything (or only other
independent stuff) and come back to check for the waiting condition next time.
do { } while(condition) will not evaluate the condition statement until after the first iteration. This
is important to keep in mind if the condition statement has side effects.
Examples
While
A while loop will evaluate its condition, and if true, it will execute the code inside and start over.
That is, as long as its condition evaluates to true, the while loop will execute over and over.
This loop will execute 100 times, each time adding 1 to the variable num:
int num = 0;
while (num < 100) {
// do something
num++;
}
The above loop is equivalent to a for loop:
for (int i = 0; i < 100; i++) {
// do something
}
This loop will execute forever:
while (true) {
// do something
}
https://riptutorial.com/
46
The above loop is equivalent to a for loop:
for (;;) {
// do something
}
For
for loops are simplified syntax for a very common loop pattern, which could be accomplished in
more lines with a while loop.
The following is a common example of a for loop, which will execute 100 times and then stop.
for (int i = 0; i < 100; i++) {
// do something
}
This is equivalent to a while loop:
int num = 0;
while (num < 100) {
// do something
num++;
}
You can create an endless loop by omitting the condition.
for (;;) {
// do something
}
This is equivalent to a while loop:
while (true) {
// do something
}
Do ... While
A do while loop is the same as a while loop, except that it is guaranteed to execute at least one
time.
The following loop will execute 100 times.
int i = 0;
do {
i++;
} while (i < 100);
A similar loop, but with a different condition, will execute 1 time.
https://riptutorial.com/
47
int i = 0;
do {
i++;
} while (i < 0);
If the above loop were merely a while loop, it would execute 0 times, because the condition would
evaluate to false before the first iteration. But since it is a do while loop, it executes once, then
checks its condition before executing again.
Flow Control
There are some ways to break or change a loop's flow.
break; will exit the current loop, and will not execute any more lines within that loop.
continue; will not execute any more code within the current iteration of the loop, but will remain in
the loop.
The following loop will execute 101 times (i = 0, 1, ..., 100 ) instead of 1000, due to the break
statement:
for (int i = 0; i < 1000; i++) {
// execute this repeatedly with i = 0, 1, 2, ...
if (i >= 100) {
break;
}
}
The following loop will result in j's value being 50 instead of 100, because of the continue
statement:
int j=0;
for (int i = 0; i < 100; i++) {
if (i % 2 == 0) { // if `i` is even
continue;
}
j++;
}
// j has the value 50 now.
Read Loops online: https://riptutorial.com/arduino/topic/2802/loops
https://riptutorial.com/
48
Chapter 18: MIDI Communication
Introduction
The intent of this topic to demonstrate some basic MIDI programs that show how to operate with
the protocol and progressively add useful features that more complex applications require.
Examples
MIDI THRU Example
The MIDI Thru is simple and easy to test. When working properly you will be able to install your
Arduino project between two MIDI devices, MIDI IN to MIDI OUT and you will be able to verify that
the two device operate together. If you have the ability to measure latency, you will see an
increase due to the serial buffer capture and re-transmit instructions.
// This is a simple MIDI THRU. Everything in, goes right out.
// This has been validate on an Arduino UNO and a Olimex MIDI Shield
boolean byteReady;
unsigned char midiByte;
void setup() {
// put your setup code here, to run once:
// Set MIDI baud rate:
Serial.begin(31250);
byteReady = false;
midiByte = 0;
}
// The Loop that always gets called...
void loop() {
if (byteReady) {
byteReady = false;
Serial.write(midiByte);
}
}
// The little function that gets called each time loop is called.
// This is automated somwhere in the Arduino code.
void serialEvent() {
if (Serial.available()) {
// get the new byte:
midiByte = (unsigned char)Serial.read();
byteReady = true;
}
}
MIDI Thru with Queue
// This is a more complex MIDI THRU. This version uses a queue. Queues are important because
https://riptutorial.com/
49
some
// MIDI messages can be interrupted for real time events. If you are generating your own
messages,
// you may need to stop your message to let a "real time" message through and then resume your
message.
#define QUEUE_DEPTH 128
// Queue Logic for storing messages
int headQ = 0;
int tailQ = 0;
unsigned char tx_queue[QUEUE_DEPTH];
void setup() {
// put your setup code here, to run once:
// Set MIDI baud rate:
Serial.begin(31250);
}
// getQDepth checks for roll over. Folks have told me this
// is not required. Feel free to experiment.
int getQDepth() {
int depth = 0;
if (headQ < tailQ) {
depth = QUEUE_DEPTH - (tailQ - headQ);
} else {
depth = headQ - tailQ;
}
return depth;
}
void addQueue (unsigned char myByte) {
int depth = 0;
depth = getQDepth();
if (depth < (QUEUE_DEPTH-2)) {
tx_queue[headQ] = myByte;
headQ++;
headQ = headQ % QUEUE_DEPTH; // Always keep the headQ limited between 0 and 127
}
}
unsigned char deQueue() {
unsigned char myByte;
myByte = tx_queue[tailQ];
tailQ++;
tailQ = tailQ % QUEUE_DEPTH; // Keep this tailQ contained within a limit
// Now that we dequeed the byte, it must be sent.
return myByte;
}
void loop() {
if (getQDepth>0) {
Serial.write(deQueue());
}
}
// The little function that gets called each time loop is called.
// This is automated somwhere in the Arduino code.
void serialEvent() {
https://riptutorial.com/
50
if (Serial.available()) {
// get the new byte:
addQueue((unsigned char)Serial.read());;
}
}
MIDI Clock Generation
// This is a MiDI clk generator. This takes a #defined BPM and
// makes the appropriate clk rate. The queue is used to let other messages
// through, but allows a clock to go immediately to reduce clock jitter
#define QUEUE_DEPTH 128
#define BPM 121
#define MIDI_SYSRT_CLK 0xF8
// clock tracking and calculation
unsigned long lastClock;
unsigned long captClock;
unsigned long clk_period_us;
// Queue Logic for storing messages
int headQ = 0;
int tailQ = 0;
unsigned char tx_queue[QUEUE_DEPTH];
void setup() {
// Set MIDI baud rate:
Serial.begin(31250);
clk_period_us = 60000000 / (24 * BPM);
lastClock = micros();
}
// getQDepth checks for roll over. Folks have told me this
// is not required. Feel free to experiment.
int getQDepth() {
int depth = 0;
if (headQ < tailQ) {
depth = QUEUE_DEPTH - (tailQ - headQ);
} else {
depth = headQ - tailQ;
}
return depth;
}
void addQueue (unsigned char myByte) {
int depth = 0;
depth = getQDepth();
if (depth < (QUEUE_DEPTH-2)) {
tx_queue[headQ] = myByte;
headQ++;
headQ = headQ % QUEUE_DEPTH; // Always keep the headQ limited between 0 and 127
}
}
unsigned char deQueue() {
unsigned char myByte;
myByte = tx_queue[tailQ];
https://riptutorial.com/
51
tailQ++;
tailQ = tailQ % QUEUE_DEPTH; // Keep this tailQ contained within a limit
// Now that we dequeed the byte, it must be sent.
return myByte;
}
void loop() {
captClock = micros();
if (lastClock > captClock) {
// we have a roll over condition - Again, maybe we don't need to do this.
if (clk_period_us <= (4294967295 - (lastClock - captClock))) {
// Add a the ideal clock period for this BPM to the last measurement value
lastClock = lastClock + clk_period_us;
// Send a clock, bypasing the transmit queue
Serial.write(MIDI_SYSRT_CLK);
}
} else if (clk_period_us <= captClock-lastClock) {
// Basically the same two commands above, but not within a roll over check
lastClock = lastClock + clk_period_us;
// Send a clock, bypasing the transmit queue
Serial.write(MIDI_SYSRT_CLK);
}
if (getQDepth>0) {
Serial.write(deQueue());
}
}
// The little function that gets called each time loop is called.
// This is automated somwhere in the Arduino code.
void serialEvent() {
if (Serial.available()) {
// get the new byte:
addQueue((unsigned char)Serial.read());;
}
}
MIDI Messages Defined
In general, MIDI protocol is broken down into "messages". There are 4 general classes of
messages:
•
•
•
•
Channel Voice
Channel Mode
System Common
System Real-Time Messages
Messages start with a byte value above 0x80. Any value below 0x7F is considered data.
Effectively meaning that 127 is the maximum value that can be encoded into a single MIDI data
byte. To encode larger values, two or more MIDI data bytes are required.
It should be pointed out that messages must be sent start to finish without interruption...
EXCEPT... System Real-Time messages, which are a single byte, which can be injected in the
middle of any message.
https://riptutorial.com/
52
Channel Voice Messages
Status
D7..D0
Data Bytes
Description
1000nnnn
0kkkkkkk
0vvvvvvv
Note Off event.This message is sent when a note is released
(ended). (kkkkkkk) is the key (note) number. (vvvvvvv) is the
velocity.
1001nnnn
0kkkkkkk
0vvvvvvv
Note On event. This message is sent when a note is
depressed (start). (kkkkkkk) is the key (note) number.
(vvvvvvv) is the velocity.
1010nnnn
0kkkkkkk
0vvvvvvv
1011nnnn
0ccccccc
0vvvvvvv
Polyphonic Key Pressure (Aftertouch). This message is most
often sent by pressing down on the key after it "bottoms out".
(kkkkkkk) is the key (note) number. (vvvvvvv) is the pressure
value.
Control Change. This message is sent when a controller value
changes. Controllers include devices such as pedals and
levers. Controller numbers 120-127 are reserved as "Channel
Mode Messages" (below). (ccccccc) is the controller number
(0-119). (vvvvvvv) is the controller value (0-127).
1100nnnn
0ppppppp
Program Change. This message sent when the patch number
changes. (ppppppp) is the new program number.
1101nnnn
0vvvvvvv
1110nnnn
0lllllll
0mmmmmmm
Channel Pressure (After-touch). This message is most often
sent by pressing down on the key after it "bottoms out". This
message is different from polyphonic after-touch. Use this
message to send the single greatest pressure value (of all the
current depressed keys). (vvvvvvv) is the pressure value.
Pitch Bend Change. This message is sent to indicate a change
in the pitch bender (wheel or lever, typically). The pitch bender
is measured by a fourteen bit value. Center (no pitch change)
is 2000H. Sensitivity is a function of the receiver, but may be
set using RPN 0. (lllllll) are the least significant 7 bits.
(mmmmmmm) are the most significant 7 bits.
Channel Mode Messages
Status
D7..D0
Data
Bytes
Description
1011nnnn
0ccccccc
0vvvvvvv
Channel Mode Messages. This the same code as the Control
Change (above), but implements Mode control and special
message by using reserved controller numbers 120-127. The
https://riptutorial.com/
53
Status
D7..D0
Data
Bytes
Description
commands are:
All Sound Off. When All Sound Off is received all oscillators will
turn off, and their volume envelopes are set to zero as soon as
possible. c = 120, v = 0: All Sound Off
Reset All Controllers. When Reset All Controllers is received, all
controller values are reset to their default values. (See specific
Recommended Practices for defaults).
c = 121, v = x: Value must only be zero unless otherwise allowed
in a specific Recommended Practice.
Local Control. When Local Control is Off, all devices on a given
channel will respond only to data received over MIDI. Played
data, etc. will be ignored. Local Control On restores the functions
of the normal controllers.
c = 122, v = 0: Local Control Off
c = 122, v = 127: Local Control On
All Notes Off. When an All Notes Off is received, all oscillators will
turn off.
c = 123, v = 0: All Notes Off (See text for description of actual
mode commands.)
c = 124, v = 0: Omni Mode Off
c = 125, v = 0: Omni Mode On
c = 126, v = M: Mono Mode On (Poly Off) where M is the number
of channels (Omni Off) or 0 (Omni On)
c = 127, v = 0: Poly Mode On (Mono Off) (Note: These four
messages also cause All Notes Off)
System Common Messages
Status
D7..D0
11110000
Data Bytes
Description
0iiiiiii [0iiiiiii 0iiiiiii]
0ddddddd --- ---
0ddddddd
System Exclusive. This message type allows manufacturers
to create their own messages (such as bulk dumps, patch
parameters, and other non-spec data) and provides a
https://riptutorial.com/
54
Status
D7..D0
Data Bytes
Description
11110111
mechanism for creating additional MIDI Specification
messages. The Manufacturer's ID code (assigned by MMA or
AMEI) is either 1 byte (0iiiiiii) or 3 bytes (0iiiiiii 0iiiiiii 0iiiiiii).
Two of the 1 Byte IDs are reserved for extensions called
Universal Exclusive Messages, which are not manufacturer-
specific. If a device recognizes the ID code as its own (or as
a supported Universal message) it will listen to the rest of the
message (0ddddddd). Otherwise, the message will be
ignored. (Note: Only Real-Time messages may be
interleaved with a System Exclusive.)
11110001
0nnndddd
MIDI Time Code Quarter Frame. nnn = Message Type dddd
= Values
11110010
0lllllll
0mmmmmmm
Song Position Pointer. This is an internal 14 bit register that
holds the number of MIDI beats (1 beat= six MIDI clocks)
since the start of the song. l is the LSB, m the MSB.
11110011
0sssssss
Song Select. The Song Select specifies which sequence or
song is to be played.
11110100
11110101
11110110
11110111
Undefined. (Reserved)
Undefined. (Reserved)
Tune Request. Upon receiving a Tune Request, all analog
synthesizers should tune their oscillators.
End of Exclusive. Used to terminate a System Exclusive
dump (see above).
System Real-Time Messages
Status
D7..D0
Data
Bytes
Description
11111000
Timing Clock. Sent 24 times per quarter note when synchronization is
required (see text).
11111001
Undefined. (Reserved)
11111010
Start. Start the current sequence playing. (This message will be
followed with Timing Clocks).
11111011
Continue. Continue at the point the sequence was Stopped.
https://riptutorial.com/
55
Status
D7..D0
Data
Bytes
Description
11111100
Stop. Stop the current sequence.
11111101
Undefined. (Reserved)
11111110
11111111
Active Sensing. This message is intended to be sent repeatedly to tell
the receiver that a connection is alive. Use of this message is optional.
When initially received, the receiver will expect to receive another
Active Sensing message each 300ms (max), and if it does not then it
will assume that the connection has been terminated. At termination,
the receiver will turn off all voices and return to normal (non- active
sensing) operation.
Reset. Reset all receivers in the system to power-up status. This
should be used sparingly, preferably under manual control. In
particular, it should not be sent on power-up.
Read MIDI Communication online: https://riptutorial.com/arduino/topic/9406/midi-communication
https://riptutorial.com/
56
Chapter 19: PWM - Pulse Width Modulation
Examples
Control a DC motor through the Serial port using PWM
In this example we aim to accomplish one of the most common tasks: I have a small DC motor
laying around, how do I use my Arduino to control it? Easy, with PWM and serial communication,
using the function analogWrite() and the Serial library.
The basics
Pulse Width Modulation or PWM for short is a technique for mimicking analog signals using digital
output. How does this work? Using a pulse train whose relation D (duty cycle) between time at
high level (digital 1, usually 5V) and time at low level (digital 0, 0V) in each period can be modified
to produce an average voltage between these two levels:
By using Arduino's analogWrite(pin,value) function we can vary the value of the duty cycle of pin's
output. Note that the pin must be put into output mode and the value must be between 0 (0V) and
255 (5V). Any value in between will simulate a proportional intermediate analog output.
However, the purpose of analog signals is usually related to the control of mechanical systems
that require more voltage and current than the Arduino board alone is capable of. In this example,
we will learn how to amplify Arduino's PWM capabilities.
For this a MOSFET diode is used. In essence, this diode acts as a switch. It allows or interrupts
the electric flow between its source and drain terminals. But instead of a mechanical switch, it
features a third terminal called gate. A very small current (<1mA) will "open" this gate and allow
the current to flow. This is very convenient, because we can send Arduino's PWM output to this
gate, thereby creating another PWM pulse train with the same duty cycle through the MOSFET,
https://riptutorial.com/
57
which allows voltages and currents that would destroy the Arduino.
Bill of materials: what do you need to build
this example
•
•
•
•
•
•
•
•
MOSFET diode: for instance, the popular BUZ11
Protection diode for the motor: Schottky SB320
Resistor: anything 10K ~ 1M Ohm
Motor: A typical small motor (a typical one can be 12V)
A power source compatible with the motor you have selected
A breadboard
Colorful cables!
An Arduino, but you already knew that.
The build
Put everything together! Power the rails of the breadboard and place the MOSFET diode in it.
Connect the motor between the positive rail and the MOSFET drain. Connect the protection diode
in the same way: between the MOSFET drain and the positive rail. Connect the source of the
MOSFET to the common ground rail. Finally, connect the PWM pin (we're using pin 10 in this
example) to the gate of the MOSFET and also to the common ground through the resistor (we
need very low current!).
Here's an example of how this build looks. If you prefer an scheme here's one.
The code
Now we can connect the Arduino to a computer, upload the code and control the motor, by
sending values through the serial communication. Recall that these values should be integers
https://riptutorial.com/
58
between 0 and 255. The actual code of this example is very simple. An explanation is provided in
each line.
int in = 0; // Variable to store the desired value
byte pinOut = 10; // PWM output pin
void setup() { // This executes once
Serial.begin(9600); // Initialize serial port
pinMode(pinOut, OUTPUT); // Prepare output pin
}
void loop() { // This loops continuously
if(Serial.available()){ // Check if there's data
in = Serial.read(); // Read said data into the variable "in"
analogWrite(pinOut, in); // Pass the value of "in" to the pin
}
}
And that's it! Now you can use Arduino's PWM capabilities to control applications that require
analog signals even when the power requirements exceed the board's limits.
PWM with a TLC5940
The TLC5940 is a handy item to have when you run out of PWM ports on the Arduino. It has 16
channels, each individually controllable with 12 bits of resolution (0-4095). An existing library is
available at http://playground.arduino.cc/Learning/TLC5940. It is useful for controlling multiple
servos or RGB LEDs. Just keep in mind, the LEDs must be common anode to work. Also, the
chips are daisy-chainable, allowing even more PWM ports.
Example:
// Include the library
#include <Tlc5940.h>
void setup() {
// Initialize
Tlc.init();
Tlc.clear();
}
unsigned int level = 0;
void loop() {
// Set all 16 outputs to same value
for (int i = 0; i < 16; i++) {
Tlc.set(i, level);
}
level = (level + 1) % 4096;
// Tell the library to send the values to the chip
Tlc.update();
delay(10);
}
Read PWM - Pulse Width Modulation online: https://riptutorial.com/arduino/topic/1658/pwm---
pulse-width-modulation
https://riptutorial.com/
59
Chapter 20: Random Numbers
Syntax
•
•
•
random(max) //Returns a (long) pseudo-random number between 0 (inclusive) and max
(exclusive)
random(min, max) //Returns a (long) pseudo-random number between min (inclusive) and
max (exclusive)
randomSeed(seed) //Initializes de pseudo-random number generator, causing it to start at a
specified point in its sequence.
Parameters
Parameter Details
min
max
The minimum possible value (inclusive) to be generated by the random()
function.
The maximum possible value (exclusive) to be generated by the random()
function.
seed
The seed that will be used to shuffle the random() function.
Remarks
If randomSeed() is called with a fixed value (eg. randomSeed(5)), the sequence of random numbers
generated by the sketch will repeat each time it is run. In most cases, a random seed is preferred,
which can be obtained by reading an unconnected analog pin.
Examples
Generate a random number
The random() function can be used to generate pseudo-random numbers:
void setup() {
Serial.begin(9600);
}
void loop() {
long randomNumber = random(500); // Generate a random number between 0 and 499
Serial.println(randomNumber);
randomNumber = random(100, 1000); // Generate a random number between 100 and 999
https://riptutorial.com/
60
Serial.println(randomNumber);
delay(100);
}
Setting a seed
If it is important for a sequence of numbers generated by random() to differ, it is a good idea to
specify a seed with randomSeed():
void setup() {
Serial.begin(9600);
// If analog pin 0 is left unconnected, analogRead(0) will produce a
// different random number each time the sketch is run.
randomSeed(analogRead(0));
}
void loop() {
long randomNumber = random(500); // Generate a random number between 0 and 499
Serial.println(randomNumber);
delay(100);
}
Read Random Numbers online: https://riptutorial.com/arduino/topic/2238/random-numbers
https://riptutorial.com/
61
Chapter 21: Serial Communication
Syntax
•
•
•
•
•
•
•
•
Serial.begin(speed) // Opens the serial port on the given baud rate
Serial.begin(speed, config)
Serial[1-3].begin(speed) // Arduino Mega only! When writing 1-3 it means you can choose
between the numbers 1 to 3 when choosing the serial port.
Serial[1-3].begin(speed, config) // Arduino Mega only! When writing 1-3 it means you can
choose between the numbers 1 to 3 when choosing the serial port.
Serial.peek() // Reads the next byte of input without removing it from the buffer
Serial.available() // Gets the number of bytes in the buffer
Serial.print(text) // Writes text to the serial port
Serial.println(text) // Same as Serial.print() but with a trailing newline
Parameters
Parameter Details
Speed
The rate of the serial port (usually 9600)
Text
The text to write to the serial port (any data type)
Data bits
Number of data bits in a packet (from 5 - 8), default is 8
Parity
Parity options for error detection: none (default), even, odd
Stop bits
Number of stop bits in a packet: one (default), two
Remarks
The Arduino Mega has four serial ports which there can be choosed from. They are accesed in the
following way
Serial.begin(9600);
Serial1.begin(38400);
Serial2.begin(19200);
Serial3.begin(4800);
The serial port on an Arduino can be set with additional parameters. The config parameter sets
data bits, parity, and stop bits. For example:
8 data bits, even parity and 1 stop bit would be - SERIAL_8E1
6 data bits, odd parity and 2 stop bit would be - SERIAL_6O2
https://riptutorial.com/
62
7 data bits, no parity and 1 stop bit would be - SERIAL_7N1
Examples
Simple read and write
This example listens for input coming in over the serial connection, then repeats it back out the
same connection.
byte incomingBytes;
void setup() {
Serial.begin(9600); // Opens serial port, sets data rate to 9600 bps.
}
void loop() {
// Send data only when you receive data.
if (Serial.available() > 0) {
// Read the incoming bytes.
incomingBytes = Serial.read();
// Echo the data.
Serial.println(incomingBytes);
}
}
Base64 filtering for serial input data
String base64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
void setup() {
Serial.begin(9600); // Turn the serial protocol ON
Serial.println("Start Typing");
}
void loop() {
if (Serial.available() > 0) { // Check if data has been sent from the user
char c = Serial.read(); // Gets one byte/Character from serial buffer
int result = base64.indexOf(c); // Base64 filtering
if (result>=0)
Serial.print(c); // Only print Base64 string
}
}
Command Handling over Serial
byte incoming;
String inBuffer;
void setup() {
Serial.begin(9600); // or whatever baud rate you would like
}
https://riptutorial.com/
63
void loop(){
// setup as non-blocking code
if(Serial.available() > 0) {
incoming = Serial.read();
if(incoming == '\n') { // newline, carriage return, both, or custom character
// handle the incoming command
handle_command();
// Clear the string for the next command
inBuffer = "";
} else{
// add the character to the buffer
inBuffer += incoming;
}
}
// since code is non-blocking, execute something else . . . .
}
void handle_command() {
// expect something like 'pin 3 high'
String command = inBuffer.substring(0, inBuffer.indexOf(' '));
String parameters = inBuffer.substring(inBuffer.indexOf(' ') + 1);
if(command.equalsIgnoreCase('pin')){
// parse the rest of the information
int pin = parameters.substring("0, parameters.indexOf(' ')).toInt();
String state = parameters.substring(parameters.indexOf(' ') + 1);
if(state.equalsIgnoreCase('high')){
digitalWrite(pin, HIGH);
}else if(state.equalsIgnoreCase('low)){
digitalWrite(pin, LOW);
}else{
Serial.println("did not compute");
}
} // add code for more commands
}
Serial Communication with Python
If you have an Arduino connected to a computer or a Raspberry Pi, and want to send data from
the Arduino to the PC you can do the following:
Arduino:
void setup() {
// Opens serial port, sets data rate to 9600 bps:
Serial.begin(9600);
}
void loop() {
// Sends a line over serial:
https://riptutorial.com/
64
Serial.println("Hello, Python!");
delay(1000);
}
Python:
import serial
ser = serial.Serial('/dev/ttyACM0', 9600) # Start serial communication
while True:
data = ser.readline() # Wait for line from Arduino and read it
print("Received: '{}'".format(data)) # Print the line to the console
Read Serial Communication online: https://riptutorial.com/arduino/topic/1674/serial-communication
https://riptutorial.com/
65
Chapter 22: Servo
Introduction
A Servo is a an enclosed system containing a motor and some supporting circuitry. The shaft of a
servo can be rotated to a fixed angle within an arc using a control signal. If the control signal is
maintained, then the servo will maintain its angle. Servos can easily be controlled with the Arduino
Servo.h library.
Syntax
•
•
•
•
#include <Servo.h> // Include the Servo library
Servo.attach(pin) // Attach to the servo on pin. Returns a Servo object
Servo.write(degrees) // Degrees to move to (0 - 180)
Servo.read() // Gets the current rotation of the servo
Examples
Moving the servo back and forth
#include <Servo.h>
Servo srv;
void setup() {
srv.attach(9); // Attach to the servo on pin 9
}
To use a servo, you need to call attach() function first. It starts generating a PWM signal
controlling a servo on a specified pin. On boards other than Arduino Mega, use of Servo library
disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on
those pins.
void loop() {
Servo.write(90); // Move the servo to 90 degrees
delay(1000); // Wait for it to move to it's new position
Servo.write(0); // Move the servo to 0 degrees
delay(1000); // Wait for it to move to it's new position
}
Note that you are not guaranteed that the servo reached the desired position, nor you can check it
from the program.
Read Servo online: https://riptutorial.com/arduino/topic/4920/servo
https://riptutorial.com/
66
Chapter 23: SPI Communication
Remarks
Chip select signals
Most slaves have an active low chip select input. So proper code to initialize and use a chip select
pin is this:
#define CSPIN 1 // or whatever else your CS pin is
// init:
pinMode(CSPIN, OUTPUT);
digitalWrite(CSPIN, 1); // deselect
// use:
digitalWrite(CSPIN, 0); // select
... perform data transfer ...
digitalWrite(CSPIN, 1); // deselect
Deselecting a slave is just as important as selecting it, because a slave may drive the MISO line
while it is selected. There may be many slaves, but only one may drive MISO. If a slave is not
deselected properly, two or more slaves might be driving MISO, which may lead to shorts between
their outputs and might damage the devices.
Transactions
Transactions serve two purposes:
•
•
tell the SPI when we want to start and end using it within a particular context
configure the SPI for a specific chip
The clock line has different idle states in the different SPI modes. Changing the SPI mode while a
slave is selected might confuse the slave, so always set the SPI mode before selecting a slave.
The SPI mode can be set with an SPISettings object passed to SPI.beginTransaction:
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
digitalWrite(CSPIN, 0);
... perform data transfer ...
digitalWrite(CSPIN, 1);
SPI.endTransaction();
SPISettings may also be stored elsewhere:
SPISettings mySettings(1000000, MSBFIRST, SPI_MODE0);
SPI.beginTransaction(mySettings);
https://riptutorial.com/
67
If another part of the code tries to use the SPI between a pair of calls to beginTransaction() and
endTransaction(), an error may be raised - how that is done depends on the implementation.
Also see Arduino Reference: SPISettings
Using the SPI in Interrupt Service Routines
If the SPI has to be used within an ISR, no other transaction may be taking place at the same
time. The SPI library provides usingInterrupt(interrupt_number) to facilitate this. It works by
disabling the given interrupt whenever beginTransaction() is called, so the interrupt cannot fire
between that pair fo calls to beginTransaction() and endTransaction().
Also see Arduino Reference: SPI: usingInterrupt
Examples
Basics: initialize the SPI and a chip select pin, and perform a 1-byte transfer
#include <SPI.h>
#define CSPIN 1
void setup() {
pinMode(CSPIN, OUTPUT); // init chip select pin as an output
digitalWrite(CSPIN, 1); // most slaves interpret a high level on CS as "deasserted"
SPI.begin();
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
digitalWrite(CSPIN, 0);
unsigned char sent = 0x01;
unsigned char received = SPI.transfer(sent);
// more data could be transferred here
digitalWrite(CSPIN, 1);
SPI.endTransaction();
SPI.end();
}
void loop() {
// we don't need loop code in this example.
}
This example:
•
•
•
properly initializes and uses a chip select pin (see remarks)
properly uses an SPI transaction (see remarks)
only uses the SPI to transfer one single byte. There is also a method for transferring arrays,
which is not used here.
https://riptutorial.com/
68
Read SPI Communication online: https://riptutorial.com/arduino/topic/4919/spi-communication
https://riptutorial.com/
69
Chapter 24: Time Management
Syntax
•
•
•
•
•
unsigned long millis()
unsigned long micros()
void delay(unsigned long milliseconds)
void delayMicroseconds(unsigned long microseconds)
See the elapsedMillis header for constructors and operators of that class. In short:
○
○
○
○
elapsedMillis elapsedMillisObject; creates an object to keep track of time since it was
created or since some other explicitly set point in time
elapsedMillisObject = 0; reset the time tracked by the object to "since now"
unsigned long deltaT = elapsedMillisObject; lets us look at the tracked time
elapsedMillisObject += and -= these work as expected
Remarks
Blocking vs. non-blocking code
For very simple sketches, writing blocking code using delay() and delayMicroseconds() can be
appropriate. When things get more complex, using these functions can have some drawbacks.
Some of these are:
•
•
•
Wasting CPU time: More complex sketches might need the CPU for something else while
waiting for an LED blinking period to end.
unexpected delays: when delay() is called in subroutines that are not obviously called, for
example in libraries you include.
missing events that happen during the delay and are not handled by an interrupt handler, for
example polled button presses: A button might be pressed for 100 ms, but this might be
shadowed by a delay(500).
Implementation details
millis() usually relies on a hardware timer that runs at a speed that's much higher than 1 kHz.
When millis() is called, the implementation returns some value, but you don't know how old that
actually is. It's possible that the "current" millisecond just started, or that it will end right after that
function call. That means that, when calculating the difference between two results from millis(),
you can be off by anything between almost zero and almost one millisecond. Use micros() if higher
precision is needed.
https://riptutorial.com/
70
Looking into the source code of elapsedMillis reveals that it indeed uses millis() internally to
compare two points in time, so it suffers from this effect as well. Again, there's the alternative
elapsedMicros for higher precision, from the same library.
Examples
blocking blinky with delay()
One of the most straight forward way of making an LED blink is: turn it on, wait a bit, turn it off,
wait again, and repeat endlessly:
// set constants for blinking the built-in LED at 1 Hz
#define OUTPIN LED_BUILTIN
#define PERIOD 500
void setup()
{
pinMode(OUTPIN, OUTPUT); // sets the digital pin as output
}
void loop()
{
digitalWrite(OUTPIN, HIGH); // sets the pin on
delayMicroseconds(PERIOD); // pauses for 500 miliseconds
digitalWrite(OUTPIN, LOW); // sets the pin off
delayMicroseconds(PERIOD); // pauses for 500 milliseconds
// doing other time-consuming stuff here will skew the blinking
}
However, waiting as done in the example above wastes CPU cycles, because it just sits there in a
loop waiting for a certain point in time to go past. That's what the non-blocking ways, using
millis() or elapsedMillis, do better - in the sense that they don't burn as much of the hardware's
capabilities.
Non-blocking blinky with the elapsedMillis library (and class)
The elapsedMillis library provides a class with the same name that keeps track of the time that
passed since it was created or set to a certain value:
#include <elapsedMillis.h>
#define OUTPIN LED_BUILTIN
#define PERIOD 500
elapsedMillis ledTime;
bool ledState = false;
void setup()
{
// initialize the digital pin as an output.
pinMode(OUTPIN, OUTPUT);
https://riptutorial.com/
71
}
void loop()
{
if (ledTime >= PERIOD)
{
ledState = !ledState;
digitalWrite(OUTPIN, ledState);
ledTime = 0;
}
// do other stuff here
}
You can see in the example that the ledTime object is assigned zero when the LED pin was
toggled. This might not be surprising at first glance, but it has an effect if more time-consuming
things are happening:
Consider a situation where the comparison between ledTime and PERIOD is done after 750
milliseconds. Then setting ledTime to zero means that all following toggle operations will be 250 ms
"late". If, in contrast, PERIOD was subtracted from ledTime, the LED would see one short period and
then continue blinking as if nothing happened.
Non-blocking blinky with millis()
This is very close to an example from the arduino docs:
// set constants for blinking the built-in LED at 1 Hz
#define OUTPIN LED_BUILTIN
#define PERIOD 500 // this is in milliseconds
int ledState = LOW;
// millis() returns an unsigned long so we'll use that to keep track of time
unsigned long lastTime = 0;
void setup() {
// set the digital pin as output:
pinMode(OUTPIN, OUTPUT);
}
void loop() {
unsigned long now = millis();
if (now - lastTime >= PERIOD) // this will be true every PERIOD milliseconds
{
lastTime = now;
if (ledState == LOW)
{
ledState = HIGH;
}
else
{
ledState = LOW;
}
digitalWrite(OUTPIN, ledState);
}
// now there's lots of time to do other stuff here
https://riptutorial.com/
72
}
Using millis() in this way - to time operations in a non-blocking way - is something that is needed
quite frequently, so consider using the elapsedMillis library for this.
Measure how long something took, using elapsedMillis and elapsedMicros
#include <elapsedMillis.h>
void setup() {
Serial.begin(115200);
elapsedMillis msTimer;
elapsedMicros usTimer;
long int dt = 500;
delay(dt);
long int us = usTimer;
long int ms = msTimer;
Serial.print("delay(");Serial.print(dt);Serial.println(") took");
Serial.print(us);Serial.println(" us, or");
Serial.print(ms);Serial.println(" ms");
}
void loop() {
}
In this example, an elapsedMillis object and an elapsedMicros object are used to measure how
long something took, by creating them just before the expression we want to time is executed, and
getting their values afterwards. They will show slightly different results, but the millisecond result
won't be off by more than one millisecond.
More than 1 task without delay()
If you have more than 1 task to execute repeatedly in different intervals, use this example as a
starting point:
unsigned long intervals[] = {250,2000}; //this defines the interval for each task in
milliseconds
unsigned long last[] = {0,0}; //this records the last executed time for each task
void setup() {
pinMode(LED_BUILTIN, OUTPUT); //set the built-it led pin as output
Serial.begin(115200); //initialize serial
}
void loop() {
unsigned long now = millis();
if(now-last[0]>=intervals[0]){ last[0]=now; firstTask(); }
if(now-last[1]>=intervals[1]){ last[1]=now; secondTask(); }
//do other things here
}
https://riptutorial.com/
73
void firstTask(){
//let's toggle the built-in led
digitalWrite(LED_BUILTIN, digitalRead(LED_BUILTIN)?0:1);
}
void secondTask(){
//say hello
Serial.println("hello from secondTask()");
}
To add another task to execute every 15 seconds, extend the variables intervals and last:
unsigned long intervals[] = {250,2000,15000};
unsigned long last[] = {0,0,0};
Then add an if statement to execute the new task. In this example, I named it thirdTask.
if(now-last[2]>=intervals[2]){ last[2]=now; thirdTask(); }
Finally declare the function:
void thirdTask(){
//your code here
}
Read Time Management online: https://riptutorial.com/arduino/topic/4852/time-management
https://riptutorial.com/
74
Chapter 25: Using Arduino with Atmel Studio
7
Remarks
Setup
•
•
Download and install Atmel Studio 7 from here.
Purchase a debugger. You can get by with a ISP programmer, but if you want debugging
capabilities, which is one of the big advantages of using Atmel Studio, you will want a
debugger. I recommend the Atmel ICE, as it provides debugging capabilities for AVR based
arduinos (like the Uno, pro mini, etc) and the ARM based Arduinos, such as the Zero and
Due. If you are on a budget, you can get it without the plastic case and be careful not to
shock it.
Connections
•
For the Uno, use the 6-pin ICSP cable. Plug one side into the Uno as shown. Plug the other
side into the debugger's AVR port.
https://riptutorial.com/
75
For the Arduino Pro Mini, use the mini squid cable as shown, again connecting the other side the
debugger's AVR port.
https://riptutorial.com/
76
Debugging considerations
For debugging with the Uno, you will need to cut the Reset-enable trace (you can always solder it
back for using with the Arduino IDE):
https://riptutorial.com/
77
Using the Pro Mini, if you intend to connect the serial port to your computer using an FTDI board,
do not connect the DTR line, as it will interfere with Atmel's Serial Wire Debug (SWD) interface. I
simply connect power, ground, Tx and Rx as shown here below. Rx and Tx on Arduino go to Tx
and Rx, respectively on FTDI board. Some FTDI boards are labeled differently, so if the serial port
doesn't work, swap Rx and Tx.
https://riptutorial.com/
78
You will have to provide power separately to the Arduino because the debugger will not power it.
This can be done on the Pro Mini through the FTDI board as shown above, or with a USB cable or
AC adaptor on the Uno.
Software setup
Plug the Atmel ICE into your computer, start Atmel Studio and you can now import an existing
Arduino project.
In Atmel Studio, go to File -> New -> Project and select "Create project from Arduino sketch". Fill
out options including board and device dropdown menus.
Go to Project -> yourProjectName Properties, click on Tool, select Atmel ICE under
debugger/programmer and debugWire under interface. Go to Debug -> Start debugging and
https://riptutorial.com/
79
break. You should see a warning and be asked if you want to set the DWEN fuse. Choose OK,
unplug the Arduino from power and plug it in again. You can stop debugging by clicking the red
square button and start by clicking the green triangle button. To return the Arduino to a state that it
can be used in the Arduino IDE, while you're debugging, choose Debug -> disable debugWIRE
and close.
Note that any functions you add must include a function prototype as well (loop and setup don't
need them). You can see the ones Atmel Studio added at the top of the sketch if there were any
functions when you imported your project into Atmel Studio (see sample code for example).
C++11 support is enabled by default in Arduino 1.6.6 and above. This provides more C++
language features and enabling it may increase compatibility with the Arduinio system. To enable
C++11 in Atmel Studio 7, right click on your project file, select properties, click on ToolChain on
the left, Click on Miscellaneous under AVR/GNU C++ Compiler and put -std=c++11 in the Other
flags field.
To include libraries in your sketch
Copy the .cpp library file into C:\Users\YourUserName\Documents\Atmel
Studio\7.0\YourSolutionName\YourProjectName\ArduinoCore\src\core, then in Atmel Studio, open the
Solution Explorer window right click on the Arduino Core/src/core folder, choose add -> existing
item and choose the file you added. Do the same with the .h library file and the
YourProjectName/Dependancies folder.
To add the terminal window
You can always have the Android IDE open and use that Serial window (just select the correct
serial port), however to add a built in Serial window to Atmel Studio, go to Tools -> Extensions and
Updates, click on Available downloads and search for Terminal Window or Terminal for Atmel
Studio and install it. Once installed, go to View -> Terminal Window.
Benefits
Programming Arduino with a moder IDE like Atmel Studio 7 gives you numerous advantages over
the Arduino IDE, including debugging, autocompletion, jump to definition and declaration,
forward/backward navigation, bookmarks and refactoring options to name a few.
You can configure key bindings by going to Tools -> Options -> Environment -> Keyboard. Some
that really speed up development are:
•
•
•
•
Edit.CommentSelection, Edit.UncommentSelection
View.NavigateForward, View.NavigateBackward
Edit.MoveSelectedLinesUp, Edit.MoveSelectedLinesDown
Edit.GoToDefinition
https://riptutorial.com/
80
Examples
Atmel Studio 7 imported sketch example
This is an example of what a simple Arduino sketch looks like after being imported into Atmel
Studio. Atmel Studio added the auto generated sections at the top. The rest is identical to the
original Arduino code. If you expand the ArduinoCore project that was created and look in the src -
> core folder, you will find main.cpp, the entry point for the program. There you can see the call to
the the Arduino setup function and a never ending for loop that calls the Arduino loop function over
and over.
/* Begining of Auto generated code by Atmel studio */
#include <Arduino.h>
/* End of auto generated code by Atmel studio */
// Beginning of Auto generated function prototypes by Atmel Studio
void printA();
// End of Auto generated function prototypes by Atmel Studio
void setup() {
Serial.begin(9600);
}
void loop() {
printA();
}
void printA() {
Serial.println("A");
}
Read Using Arduino with Atmel Studio 7 online: https://riptutorial.com/arduino/topic/2567/using-
arduino-with-atmel-studio-7
https://riptutorial.com/
81
Chapter 26: Variables and Data Types
Examples
Create variable
To create a variable:
variableType variableName;
For example:
int a;
To create a variable and initialize it:
variableType variableName = initialValue;
For example:
int a = 2;
Assign value to a variable
If you have a variable declared before, you can assign some value to it:
For example:
int a; // declared previously
a = 2;
Or change the value:
int a = 3; // initalized previously
a = 2;
Variable types
•
•
•
•
•
•
char : signed 1-byte character value
byte : unsigned 8-bit integer
int : signed 16-bit (on ATMEGA based boards) or 32-bit (on Arduino Due) integer
unsigned int : unsigned 16-bit (on ATMEGA based boards) or 32-bit (on Arduino Due)
integer
long : signed 32-bit integer
unsigned long : unsigned 32-bit integer
https://riptutorial.com/
82
•
•
float : 4-byte floating point number
double : 4-byte (on ATMEGA based boards) or 8-byte (on Arduino Due) floating point number
Examples:
char a = 'A';
char a = 65;
byte b = B10010;
int c = 2;
unsigned int d = 3;
long e = 186000L;
unsigned long f = millis(); // as an example
float g = 1.117;
double h = 1.117;
Read Variables and Data Types online: https://riptutorial.com/arduino/topic/2565/variables-and-
data-types
https://riptutorial.com/
83
Credits
S.
No
1
2
3
4
5
6
7
8
9
Chapters
Contributors
Getting started with
arduino
Abhishek Jain, Christoph, Community, Danny_ds, Doruk,
geek1011, gmuraleekrishna, H. Pauwelyn, jleung513, Martin
Carney, Mizole Ni, Shef, uruloke, Wolfgang
Analog Inputs
Jake Lites, MikeS159, Ouss4, uruloke
Arduino IDE
geek1011, Jeremy, jleung513, sohnryang, uruloke
Audio Output
Jake Lites, MikeCAT
Bluetooth
Communication
Girish, Martin Carney
Data Storage
Danny_ds, robert
Digital Inputs
Martin Carney, uruloke
Digital Output
uruloke
Functions
datafiddler, Leah, MikeCAT
10 Hardware pins
Jeremy, Martin Carney
11
12
How Python
integrates with
Arduino Uno
How to store
variables in
EEPROM and use
them for permanent
storage
Danny_ds, Peter Mortensen, Stark Nguyen
AZ Vcience, Chris Combs, Danny_ds, Jeremy, Peter Mortensen
, RamenChef
13
I2C Communication
Asaf
14
Interrupts
DavidJ, Martin Carney
15
Libraries
Oscar Lundberg
16
Liquid Crystal Library Morgoth
17
Loops
datafiddler, Martin Carney, MikeCAT
https://riptutorial.com/
84
18 MIDI Communication Rich Maes
19
PWM - Pulse Width
Modulation
Danny_ds, Johnny Mopp, JorgeGT, Martin Carney
20 Random Numbers
Danny_ds, Javier Rizzo Aguirre, MikeCAT
21
Serial
Communication
blainedwards8, Danny_ds, geek1011, Leah, Martin Carney,
MikeS159, Morgoth, Nufail Achath, Peter Mortensen, uruloke
22 Servo
geek1011, mactro, Morgoth
23 SPI Communication
Christoph
24
Time Management
Christoph, Rei
25
26
Using Arduino with
Atmel Studio 7
Variables and Data
Types
Danny_ds, Nate
Leah, MikeCAT
https://riptutorial.com/
85
|