LongCut logo

Fully automating Arduino development - Giving Claude Code access to hardware 🤖⚡️💻

By Adafruit Industries

Summary

Topics Covered

  • AI Takes the Wheel in Hardware Debugging
  • Break Tasks Into Five-Step Cycles
  • 60 Cents to Semi-Automated Driver Development
  • Automated Hardware CI Finally Within Reach
  • Use AI for Python Hardware Projects

Full Transcript

all right lady what is this okay so this is a really interesting project I'm doing right now this is a Metro mini so it's an Arduino compatible this is a little sensor and I purposely am picking a sensor that's not particularly

complicated this is the opt 4048 and this is a tri stimulus color sensor it's basically a light color sensor and what um I'm doing is I'm experimenting with

this new llm technology that just came out called Claud code and CLA code is like I've used Claude a bunch of times it's an llm where you you have a window

and you type back and forth or use the API you use like a whatever some goey and sometimes you can use stuff like cursor where it's embedded in um your editor but I've never really liked the

embedded editor part of um cursor I really like to kind of work with my files and also something that's very interesting about Cloud code is it gives you shell access to the llom which like

I think if I told myself two years about this ago about this they'd be like this is incred stupid why would you give this like crazy AI access to your shell but uh you know what like we're living in

amazing times so the fact that I can tell Claude now how to run shell commands means I can have it automatically compile code for you know

Arduino compatibles with the Arduino CLI and then upload the code and then check the output and fix the code so I have like a full debugging cycle um where I'm

like you know there I'm like driving the car but I have this co-pilot that's like telling me where to go so we do it together I'll show you how it works um through the command line tool it's kind

of like a weird cross between like IRC and like a BBS or whatever and and also using like cmake um but just to show you so this Hardware is connected to my computer like I said ardino compatible

and it's got this little sensor connected over iort C so now let's go to the computer um so like I said if you want to install Cloud code I think it's

out of preview so you can install it I'm running Windows I say just like I'll have some hints up later but basically if you're running Windows 10 you need to be running Windows 11 to do Hardware

interaction because you'll get through like the cloud installation and then you'll realize you have no way to access the USB device and you have to access the U USB device

using USB ipd which is the WSL that's Windows subsystem Linux way of getting Hardware that would normally be here it's not appearing here because I've

bound it into WSL now you're probably why am I using WSL because Cloud code doesn't run on Windows native yet so there's a lot of these like weird ass workarounds I'm doing just because it doesn't run on Windows natively yet why

I don't know I'm sure they're working on it I'm sure Claude and people who tend to Claude are like going back and forth but it does work under WSL I'm using

Debian in this case um there's uh tutorials on on how to do USB ipd but basically um you know you have these you know devices and in this case I've

attached the silabs chip which is the USB serial chip comport into Debian and

so in my Debian desktop here I've got make this nice and big um it shows up here and then I've

got uh TT y usb0 right I've got this um I've got access to the serial device through um WSL not through Windows

proper okay now that you'll have to install like ardino CLI and you'll have to install some other tools whatever and like you know I'm not going to go through all that so the way I've kind of

come up with this like workflow and I'm using this I'm just using notion which is like a way of like having text with easy way to copy and paste it is I'm trying to come up with like prompts that

I can kind of recycle and reuse use and one thing that's like you know as I'm doing this is frustrating is of course like llms have this like Randomness in it so you running the same prompt over

and over doesn't always get you the same output but you can kind of sort of tweak The Prompt until um it gets really close so one of the things I'm doing is um

I'll show on my main screen you know there's the data sheet right but the data sheet is massive and also it's like weirdly formatted and llm only work with

text so what we have to tell it to do and I do this in the initial prompt is I you know I kind of give it some ideas of like how the style blah blah blah and

then um convert the PDF into a text file so for example where's my thing okay so here I've created another thing I've done is I've separated the Arduino like

I've created a separate folder for like my Arduino work um so it doesn't touch like my main library folder um and in this folder I created like a new library

opt 4048 and I have the PDF file the PDF file is like the data sheet so now you launch Claude after you've done the npm install and it's like hi I'm here I'm

ready and like I said you know one thing I did oh by the way you need an API key for this and it's not super cheap so just be where you're you're going to be burning API queries but I kind of ran

this over and over again until I sort of I feel like I got very close um so I'm kind of running this live hopefully it'll work um if it doesn't I'll try to

fix it so I paste in you know my prompts and like I said you know a lot of the prompt is just telling it like please don't write all of the code at once but it kind of does anyways because it's

Claud 37 for everything you want to do reading files writing to files diffs Etc it'll tell you like for example it wants to run this bash command and I can tell

it you know you can run it this time you can always run PDF to text I'll just for now I'll just say yes and you can see it's kind of got this like nice

curses you know colorful boxes um I kind of feel like I'm like back in like the 90s okay so now it's converted it it reads the text and what's interesting is

I think that this is how like chat GPT was reading PDFs because I was like I'd upload a PDF and I was like how are you reading like how are you parsing it and I think it was just using PDF to text so if not I don't know I'll find other

tools um I don't know if converting it to mark would be any better okay so what's nice is that it gives you a diff and like my text is really big um again

I think once they get you know this going it'll be more integrated with an IDE um so what's nice is that it tells me like okay you know it has the doxygen formats I've asked it for I tell it to

use busio I tell it okay please just make that register map like all of the registers in the data sheet and give me little um information and you start with just the instantiator

and the begin and then it says do you want to make these edits what's nice is that it doesn't make changes even though it has right access to files in the directory it doesn't automatically do it

unless like I tell it um know talking to someone who does a lot of like work with machine learning and I was I was explaining how I use llms and she was like yeah like because you do open

source you get to treat it differently because you're like use all the history of my stuff okay now it's going to write the CPP file ditto it kind of copies my standard boiler plates you know license

text the header it does the Ice quiry device delete create you know you can pass in the wire you can pass in a separate iport C address in this case what's interesting

is I actually told it not to do this yet but it did it and I don't know if it's because I've run this prompt so many times that it's like been added to some history somewhere but anyways it creates

the CPP file so this is actually where I would normal like I've done this with Claude and I've gone here and I would actually just copy like literally I just copy and paste all this text in say make the header make the test here's the I

know that's the test example it creates the object it starts serial I tell it I always want this bod rate and then halt if you can't find it and then do nothing

else um so where it gets interesting is like okay now it's like okay I've created those files and I you know I saved them to the file system great um

in this case I already did this but I'm going to I'm just going to copy like I said it kind of skipped ahead I I told it like don't write the test function but it wor the test function anyways now

what's cool is I've edited the prompts to now ask it can you check if you've already done this because one thing I've noticed with Claud code is it doesn't save your context at all there's no way

to like you can compact it and you can tell it to write to like a markdown file but basically every time you connect like as usual with an llm it's like a

totally fresh connection okay uh um next up that's where it gets interesting we can actually tell it okay let's um compile the code with Arduino CLI I

installed Arduino CLI and I tell it you know if you're having issues use the verbose mode but let's just try getting it compiling um use the sketch you know I

tried to make this generic so that I can reuse this prompt for other chips without having to like tweak and edit the prompt hopefully this is gonna work okay

cool it was able to compile it um and you can see it does give you the output and I think I told it like use verbose mode Let's see or it used verbose mode I

don't know I didn't ask it to why is it taking so long I think the first time it compiles it takes a while right get a little bit nervous when it's

just sitting here for like 30 seconds what are you doing it's compiled actioning I think I'm going to just to stop okay it compiled now let's

try uploading I don't know it kind of went there okay so now I'm telling it to like I said every time you run it it's like

it's not um determinant it's indeterminate okay so it found the USB port because I tell it to run board list so it finds the port and then that's how it knows what my USB port's called and

then then the first thing I do is actually I don't upload the test sketch it wrote I actually tell it to upload the icor C example from Adafruit test

bed and the reason I do that um you can see this this was just blinking is I wanted to verify the harbor connection and also just to verify like it can actually do the upload second I wanted

to get the serial output right because I want to see like did this work so I use grab seral you can use stty you can use like whatever but the trick is you know it's not you need to tell it to like do

a timeout or like don't it doesn't know how to quit things I don't think I think it only runs in non-interactive mode so just make sure any bash commands you want it to run are not interactive so in

this case you know it tells you the output and I say you know look for the iort C address ox44 which it finds and it's like great now I can continue with

uploading the sketch it uploads the sketch and then now I'm going to tell it check the output and then this is get interesting cuz like sometimes I run it

oh yeah it works sometimes it gets the bytes the you know I chip ID backwards and it does eventually like I don't didn't record it but it got the bite order backwards it thought it was like

ox 2108 when did the comparison but then by reading the output and I told it like well try to fix it based on what you see the ice squir c um traffic is it was able to say like oh I see what happened

like I have to swap the bites so that's kind of neat um but that's how far I've gotten so how far I've gotten so far um but I think this is like you know the

hardest part for me is getting the context started because now I can just say like okay let's just go and do all the registers and then for each register like what I do is I have on my side

monitor here the data sheet because I don't trust um the llms like they do make mistakes especially as the context get started along and they start to like get

confused so what I do after you know once I get like okay it's started I say like okay let's go through the register map and um let's see find where the register map

is because this is like how to use it okay so I say like Okay add Setters and Getters for like you know the register map the exponent and the LSB like it you it

probably could do an okay job but I found that so far like because drivers are complicated it works best if I sort of tell it like okay like go forward five steps and then like let's test that

and then go for another five steps um so the next thing I would do is probably you know have like the operating mode add um Getters for all of these like

counters and stuff and then eventually I'll tell it okay now convert this data into like the Lux or XYZ data and do the test so I'm kind of interested you know

it's like I said I've used CLA code and Sonet for Hardware work before but it's always been me just like doing this copy paste B back and forth um you know a

little little um delicately trying to make sure that I especially again as a as a context gets long it can start rewriting the wrong things trying to make sure that I'm getting everything in the right spot um what's neat also is

there's a couple other extra things built in which I haven't used yet but I'm interested in one is you can compact the conversation and then another thing and then you can also do cost you can

say you know like how much how much does this cost 60 cents um this is not bad it's like a arcade you know it's like yeah two it's like a token two two Pac-Man runs inflation man

there's there's another thing I'll say I can't quite figure out how you get there but there was a way you can go up to look at previous commands but there was

a way to get to like the conversation and Fork it off but I don't remember how I got there I have to like some like special command but um anyways cool stuff uh I think this is like the first

time like we've got an automated Hardware let's take this one offline yeah it's like let's do Hardware you know development fully um you know like

having that um Hardware workflow where it like does the coding and tests and even like I'll tell you I wouldn't again I wouldn't use it for like the high level thinking of how a driver should run but like stuff like oh there's a

compiler error or like I forgot a type de you know if if I didn't copy and paste something right it'll it'll fix little bugs like oh oh you know I thought there was an underscore and there wasn't it will see the compiler

error and then it'll just fix it so I think for um Library development it's going to be kind of neat Hardware development you know people always ask me like how come you can't do continuous integration with hardware and I'm like how would you have

automated like upload and then look at the output and know what it meant but I think uh you know we're getting close to it now anyways check this out well you know I'm sure the these uh techniques

and more are in apple and they've got something yeah no they have something but it's like it doesn't make sense for no one's ever we'll never know it's a secret sauce with so many things so this

is cool this is like we're making Advanced Manufacturing in in a in a unique way yeah so I'm GNA for 60 cents for 60 cents I mean it's a it's a bar I will say you know it's you are paying

per token so it's not going to be as cheap as the flat $20 fee but like if I can you know getting it to this point and then again continuing on with the driver I'm going to try it out I haven't actually got like I just got this

working to the state where it's like okay I can consistently get it to upload code and check the output um and the next step is to do this but like I feel like I'm getting

closer to having a like semi-automated way of doing driver development which is like very tedious and this also be very interesting for um circuit Python and python Hardware development you know

because again like cloud is really good at python they all are so that's the thing it's like almost a native language yeah anyways so that's uh that's my desk

Loading...

Loading video analysis...