{"id":1101,"date":"2021-05-17T13:02:22","date_gmt":"2021-05-17T17:02:22","guid":{"rendered":"https:\/\/dc540.org\/xxx\/?p=1101"},"modified":"2021-05-17T13:02:22","modified_gmt":"2021-05-17T17:02:22","slug":"fun-with-the-pico-and-c","status":"publish","type":"post","link":"https:\/\/dc540.org\/xxx\/2021\/05\/fun-with-the-pico-and-c\/","title":{"rendered":"Fun with the Pico and C"},"content":{"rendered":"\n<p>When I finally got my hands on some Pico microcontrollers, I was excited to see what they could do. But I was used to the Arduino infrastructure and wanted to explore the Pico on its own terms.<\/p>\n\n\n\n<p>Obviously MicroPython is the easy choice. Once the Pico is flashed with MicroPython firmware, you can write your code in Thonny and just save it straight to the Pico from within Thonny. Easy peazy.<\/p>\n\n\n\n<p>Coding in C requires a bit more effort, especially at the start. You need to get the compiler installed, which varies by OS, and since I develop on a Mac with the M1 Silicon chip, it&#8217;s even more obscure for me. Fortunately, it&#8217;s all right there in the docs. Specifically, the &#8220;<a href=\"https:\/\/datasheets.raspberrypi.org\/pico\/getting-started-with-pico.pdf\">Getting Started<\/a>&#8221; document, chapter 9, page 37. An architecture flag allowed the brew command to work, and I was off to the races.<\/p>\n\n\n\n<p>Pin stuff is easy. I know I can do that. I wanted to skip to some wacky complicated stuff. So I started with the Waveshare demo for the Waveshare Pico-LCD-1.14 display hat with buttons. I decided i wanted to modify that demo to display my own image instead of the stock image. After some trial and error, I was sort of able to do so.<\/p>\n\n\n\n<p>The image is stored as a c hex array. Getting that file exactly right was time-consuming. I didn&#8217;t see an image converter in their examples arsenal, so I found <a href=\"http:\/\/www.digole.com\/tools\/PicturetoC_Hex_converter.php\">this one<\/a> online. By tweaking the settings a bit I was able to get an image to display .. sort of. The color mappings are different somehow. Maybe 65K colors isn&#8217;t that many after all. I&#8217;ll have to mess with it with a more legible photo.<\/p>\n\n\n\n<p>Original photo for reference:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/dc540.org\/xxx\/wp-content\/uploads\/2021\/05\/picoleds-1024x768.jpg\" alt=\"\" class=\"wp-image-1104\" srcset=\"https:\/\/dc540.org\/xxx\/wp-content\/uploads\/2021\/05\/picoleds-1024x768.jpg 1024w, https:\/\/dc540.org\/xxx\/wp-content\/uploads\/2021\/05\/picoleds-350x263.jpg 350w, https:\/\/dc540.org\/xxx\/wp-content\/uploads\/2021\/05\/picoleds-300x225.jpg 300w, https:\/\/dc540.org\/xxx\/wp-content\/uploads\/2021\/05\/picoleds-768x576.jpg 768w, https:\/\/dc540.org\/xxx\/wp-content\/uploads\/2021\/05\/picoleds-1536x1152.jpg 1536w, https:\/\/dc540.org\/xxx\/wp-content\/uploads\/2021\/05\/picoleds.jpg 2048w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"103\" src=\"https:\/\/dc540.org\/xxx\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-17-at-12.50.34-PM-1024x103.png\" alt=\"\" class=\"wp-image-1102\" srcset=\"https:\/\/dc540.org\/xxx\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-17-at-12.50.34-PM-1024x103.png 1024w, https:\/\/dc540.org\/xxx\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-17-at-12.50.34-PM-350x35.png 350w, https:\/\/dc540.org\/xxx\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-17-at-12.50.34-PM-300x30.png 300w, https:\/\/dc540.org\/xxx\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-17-at-12.50.34-PM-768x77.png 768w, https:\/\/dc540.org\/xxx\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-17-at-12.50.34-PM-1536x155.png 1536w, https:\/\/dc540.org\/xxx\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-17-at-12.50.34-PM-2048x206.png 2048w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<p>The display is 240&#215;135 and 65K colors. I&#8217;ll update this post when I figure out more. This is just to make it a little bit easier for those who want to get into C programming on the Pico but don&#8217;t know where to start. <\/p>\n\n\n\n<p>Also, these kids will show you the general build environment \/ compile process <em>completely<\/em> if you live in Ubuntu-land. Amazing.  <\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"C Code To Raspberry Pi Pico Firmware Walkthrough\" width=\"525\" height=\"295\" src=\"https:\/\/www.youtube.com\/embed\/g3db_zsrXj8?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>When I finally got my hands on some Pico microcontrollers, I was excited to see what they could do. But I was used to the Arduino infrastructure and wanted to &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/dc540.org\/xxx\/2021\/05\/fun-with-the-pico-and-c\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Fun with the Pico and C&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":1103,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[5],"tags":[],"class_list":["post-1101","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hardware"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/dc540.org\/xxx\/wp-content\/uploads\/2021\/05\/display.jpeg","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/dc540.org\/xxx\/wp-json\/wp\/v2\/posts\/1101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dc540.org\/xxx\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dc540.org\/xxx\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dc540.org\/xxx\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dc540.org\/xxx\/wp-json\/wp\/v2\/comments?post=1101"}],"version-history":[{"count":1,"href":"https:\/\/dc540.org\/xxx\/wp-json\/wp\/v2\/posts\/1101\/revisions"}],"predecessor-version":[{"id":1105,"href":"https:\/\/dc540.org\/xxx\/wp-json\/wp\/v2\/posts\/1101\/revisions\/1105"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dc540.org\/xxx\/wp-json\/wp\/v2\/media\/1103"}],"wp:attachment":[{"href":"https:\/\/dc540.org\/xxx\/wp-json\/wp\/v2\/media?parent=1101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dc540.org\/xxx\/wp-json\/wp\/v2\/categories?post=1101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dc540.org\/xxx\/wp-json\/wp\/v2\/tags?post=1101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}