#circuitpython-dev

1 messages Β· Page 128 of 1

tulip sleet
#

Looking at the examples, I would just put them inside the class and put an underscore on the front.

tidal kiln
#

and the answer to that question decides location? that's kind of how i see it also

#

but not sure if that's residual c brain getting in the way of the pythonic way

tulip sleet
#

pick the narrowest namespace scope needed, which is inside the class

tidal kiln
#

and lo, PEP8 sayeth unto the world "Constants are usually defined on a module level and written in all capital letters with underscores separating words."

tulip sleet
#

i guess the lookup will be faster because you won't have to say self.CONST

#

inside the class

tidal kiln
#

which is probably more important than the namespace protection? thus the pep8 wording?

tulip sleet
tidal kiln
#

ha! has pretty much every possible question been asked on s.o.???

idle owl
#

Yeah I'd say so

tulip sleet
#

trying an experiment... hold on..

tidal kiln
#

but has no discussion or mention about your self. point

tulip sleet
#

foo.py:

_MODULE_CONST = const(1)

class C:
    _CLASS_CONST = const(1)
    print(_MODULE_CONST, self._CLASS_CONST)
$ strings ~/foo.mpy
<module>
/home/halbert/foo.py
/home/halbert/foo.py
__name__
__module__
__qualname__
print
self
_CLASS_CONST
#

so the _MODULE_CONST disappears, but the _CLASS_CONST does not. So for CPy/MPy the module consts would be faster, but I would say it's better programming practice to put them in the class.

#

so it's a dilemma

#

we are worried about space, so module consts are probably better, if they are really const()

tidal kiln
#

whats the better prog pactice argument?

tulip sleet
#

put them in the namespace that uses them

tidal kiln
#

yep

tulip sleet
#

but our code is small, so it's all readable anyway, one way or the other

tidal kiln
#

interstingly, those two examples seem to do the opposite

#

the one that could be class level is module level

#

while onewire.py hides some globally useful onewire defines in the class

tulip sleet
#

i wouldn't read a lot into the code there - it doesn't necessarily reflect best practice either way

#

wait, the self._CLASS_CONST isn't necessary, I think.

tidal kiln
#

yep. but i'm refactoring it. so kind of have to deal with it. one way or another.

#

mpy-cross must take care of that then?

tulip sleet
#

trying something else... hold on...

#

kinda a violation of what you'd expect to work:

#
from micropython import const

_MODULE_CONST = const(1)

class C:
    _CLASS_CONST = const(1)
    def __init__(self):
        pass

    def pr(self):
        print(_MODULE_CONST, _CLASS_CONST)
#

that works in MPy/CPy, but this doesn't work in regular python:

_MODULE_CONST = 1

class C:
    _CLASS_CONST = 2
    def __init__(self):
        pass

    def pr(self):
        print(_MODULE_CONST, _CLASS_CONST)
 python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import foo1
>>> c = foo1.C()
>>> c.pr()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/halbert/foo1.py", line 9, in pr
    print(_MODULE_CONST, _CLASS_CONST)
NameError: name '_CLASS_CONST' is not defined
>>>
#

so the substitution happens at compile time, kinda bizarre

tidal kiln
#

but understandable

tulip sleet
#

so I'd do module-level, so that the code could transfer to regular python, without an extensive rewrite aside from removing the const(). Then we gain the benefit of the .mpy's and are still closer to compatible.

#

but keep thinking about it as you rewrite

tidal kiln
#

i think you've answered it

#

also, 99.9% of whats been written is module level

#

thanks for the input!

tulip sleet
#

yw! (watching a live guitar lesson at same time)

tidal kiln
#

planning to try out for Toolchain Pain?

tulip sleet
#

only acoustic - no heavy metal, more like Python, Paul, and Mary

#

(took a long time to come up with a mediocre jjoke)

idle owl
#

@tulip sleet You're in for Toolchain Pain Unplugged.

#

@tulip sleet Do I remember right that we have erasers for nonexpress boards?

tulip sleet
idle owl
#

ah ok.

#

Ok nice!

#

Thanks

tulip sleet
#

I'll merge that into master when I do the next update merge from 2.x

manic glacierBOT
#

Take a look at latest when you get a chance. I created a new repo for the working code:
https://github.com/caternuson/OneWire-Stuff
This will all probably live in different libraries when done but helps to have in one place for now. Copy all three files over and should be able to run the basic demo:

>>> import board
>>> import adafruit_onewirebus
>>> import adafruit_ds18x20
>>> ow_bus = adafruit_onewirebus.OneWireBus(board.D2)
>>> ds18 = adafruit_ds18x20.DS18X20(ow_bus, ow_b...
manic glacierBOT
azure wigeon
#

Hi. I am having some trouble installing CircuitPython on my Circuit Playground Express. I am following the UF2 install instructions but when I copy the UF2 file onto the CPLAYBOOT disk it doesn't work as expected. The flash seems to work, but the new disk which appears has no name (should be CIRCUITPY) and I can't copy any files to it because it claims to be full. I can connect to the repl using screen, though.

#

1/ Is this the right place to ask for help with that?
2/ What might be the problem here?

azure wigeon
#

Trying to write a file to the storage from python gives OsError 30, (ie read-only FS). I'm worried that I have damaged the flash storage 😦

solar whale
azure wigeon
#

Thanks I'll try that

stuck elbow
#

by the way, to write files from python, you need to switch in yout boot.py to read-only for USB

#

it's to prevent corrupting the files when both sides write something

azure wigeon
#

@solar whale yes- that has fixed it. Thank you!

#

@stuck elbow good to know, thanks

solar whale
#

@azure wigeon great! If you want to write from CircuitPython, there is a guide. Just need a few minutes to find it.

tulip sleet
#

<@&356864093652516868> A user in the forums asked about using MQTT with CircuitPython: https://forums.adafruit.com/viewtopic.php?f=60&t=127356. I'm not familiar but I referred them to @bronze geyser 's writeup (https://bitknitting.wordpress.com/2017/11/04/using-mqtt-on-circuit-python/) and also to here.

formal plover
#

@tulip sleet Awesome. We also have information on using Adafruit IO API calls

#

I'm not sure if it's officially documented though.

#

Since I've been out

idle owl
#

@formal plover Hey Kurt!

formal plover
#

@idle owl Hello!!!

#

Trying to prep/get back in the swing of things

#

Lol

idle owl
#

Totally understandable!

#

@tulip sleet Yeah HappyDay's writeup is the only MQTT thing of that nature I'm aware of. That's what I would have suggested as well.

stuck elbow
#

from the micropython forums I remember that the mqtt stuff worked pretty well, but I never got into IoT myself

manic glacierBOT
opaque patrol
#

So, my plans for today was to look at the problem with the mu-editor on the com port, but I got an email from them about an issue that Lady Ada just fixed. Good news - works wonderfully, bad news - what to do? hmmm microcenter has feather m0 adaloggers in stock.......πŸ˜ƒ

idle owl
#

Good problems to have? πŸ˜ƒ

tawny creek
#

@stuck elbow did you mean, make boot.py read-only?

idle owl
#

@cascade#3765 No, it's using boot.py to set the flash as read-only to either CircuitPython or the system it's hooked up to via USB. Only one at a time can have write.

bronze geyser
#

@tulip sleet Please lemme know if I can answer any ?

#

@tulip sleet oops...regarding mqtt on circuit python (the port i did)...it was simple...

idle owl
#

@bronze geyser You could check out the forum post and respond there if you have anything to add πŸ˜ƒ

bronze geyser
#

@tulip sleet ...of course, now - greedy thingy that i am - I want interrupts so I can do LoRa...or I have to think about a LoRa w/ UART.

idle owl
#

Getting fancy!

bronze geyser
#

@idle owl oh righto. I will go there now. Usually I don't have anything meaningful to add. However, this doesn't seem to dissuade me from well...just rambling on and on and on and on...

idle owl
#

@bronze geyser And yet you always end up explaining something useful. πŸ˜‰

bronze geyser
#

My you are kind @idle owl. Thank you.

idle owl
#

@bronze geyser The original post was rather simple, not a lot of detail to the question, but if you get on the thread you can have it notify you when someone posts to it. Then you would be able to answer if they have more questions πŸ˜ƒ

bronze geyser
#

@idle owl -> again, many thanks.

idle owl
#

You're always welcome!

wraith tiger
#

I appear to have a not fully functional Feather M0 express. It appears to be running a blinky type program, cycling through the colors on the neopixel, but the block device portion doesn't seem to be working properly. It doesn't show up on windows 7, windows 10, linux or macOS.

#

Are there any tricks that might rescue it or should I just contact customer support about a replacement?

idle owl
#

It's likely that the file system is corrupted. Does it show up as FEATHERBOOT if you tap the reset button twice?

wraith tiger
#

IT just came up with "Installing device driver software".

idle owl
#

What OS are you currently on?

wraith tiger
#

Windows 7

idle owl
#

Did it ever show up on Win7 for you? Or is this your initial attempt to use it.

wraith tiger
#

Threee of the four show up as "Ready to use".

#

The M0 is still searching Windows update.

#

Now FEATHERBOOT shows up.

idle owl
#

Ok that's good!

wraith tiger
#

All the driver installs competed.

idle owl
#

You're trying to work with CircuitPython, correct?

wraith tiger
#

I tried to use it last night and this morning and the block device never showed up.

idle owl
#

Ok, then let's get CP flashed to your board. If that fails, it's a file system issue. It might simply have needed the drivers installed. Have you downloaded the latest version of CircuitPython for the Feather M0 Express?

wraith tiger
#

Yes, I'll try circuit python first but I also updated the Arduino IDE .

idle owl
#

Nice!

wraith tiger
#

I've messed about a bit with an Arduino Uno previously.

idle owl
#

Ok, once CP is installed, you can simply load an Arduino sketch to get started with Arduino, and then follow the steps we're about to do to get CP back on if you want to try it again.

#

So, have you downloaded the latest CircuitPython? I can link it if not

wraith tiger
#

I'm downloading the Feather m0 express uf2 file from github.

idle owl
#

Excellent!

#

Once it's downloaded, drag it to FEATHERBOOT. It'll flash a bit, and then it should disconnect on it's own, reset and then mount as CIRCUITPY.

wraith tiger
#

OK, done. Now CIRCUITPY shows up.

idle owl
#

Nice!

wraith tiger
#

OK, the blinky from the guide appears to be running properly.

idle owl
#

That's great! Nice job πŸ˜ƒ

wraith tiger
#

Thanks for your help.

idle owl
#

Yeah for sure! You're welcome

wraith tiger
#

I'm kicking myself for not realizing that I should have bought some female headers to connect the joy featherwing & feather.

#

I'll just have to mess with breadboard jumper for now.

idle owl
#

I forgot the first time I ordered a featherwing too. Ended up ordering a Feather Doubler eventually. But it was breadboard all the way at first. πŸ˜„

wraith tiger
#

Yeah, I hope to end up with a semi compact device that I'll try to design a case to 3d print for.

idle owl
#

Ah then headers will indeed be your friend there.

wraith tiger
#

I'll be experimenting with truning it into a HID.

idle owl
#

Oh nice

wraith tiger
#

I'm wondering if it would be possible for one device to be a keyboard and mouse at the same time.

idle owl
#

That one I'm not sure about.

wraith tiger
#

Hopefully either that or toggling back and forth in software will work.

#

Well, I'm off to lunch. Thanks again.

idle owl
#

You're welcome! Have a good one!

glacial bronze
#

You'd have to build a custom USB descriptor for a composite device, but it could be done

#

But besides being tied to a Linux library, the resulting device will have no Windows drivers and may not be usable outside of a *nix environment

#

So I'd suggest actually implementing a USB hub and separate mouse and keyboard controllers into the project.

#

The FE1.1s is a popular and easy to use USB hub IC that's gotten a lot of use and open source board designs in the Raspberry Pi community that you could adapt or buy outright

#

Adafruit even stocks one from Pimoroni I think

tulip sleet
#

<@&356864093652516868> who are Atom editor users: simple experimental package that does the equivalent of Eject on Windows or sync on Linux to ensure that the file you write to CIRCUITPY is completely written immediately. Go to Atom Preferences->Install->Packages and search for circuitpython-force-to-drive. https://atom.io/packages/circuitpython-force-to-drive

Atom

When saving to a CIRCUITPY drive, make sure the file is completely written out immediately.

tidal kiln
#

@slender iron just ran cookiecutter to start a new lib. said 'no' to depends on register. but it still put it in the README. expected?

slender iron
#

@wraith tiger @glacial bronze CircuitPython is set up as a mouse and keyboard by default now.

#

@tidal kiln yeah, because empty is false and anything non-empty is true

glacial bronze
#

As both?

#

At once, I mean

slender iron
#

@glacial bronze yes, with a composite descriptor

#

@tidal kiln I should switch it to a choice

glacial bronze
#

Neat

tidal kiln
#

ah. the inputs are simple. if input then foo

slender iron
#

yeah

tidal kiln
#

yes and no are both true πŸ˜‹

slender iron
#

yeah unfortunately

#

@tidal kiln if you are just cookiecuttering hold off a bit

#

I have an update PR for it

tidal kiln
#

ok. a few steps in, but not too much if you want me to start over.

slender iron
#

@tulip sleet take another look. I added a note about looking it all over

tulip sleet
#

@slender iron I had to fix a library with non-standard capitalization. Is it worth say the library folder name is always lowercase, but the library name can be properly capitalized? Or do you think that's obvious.

slender iron
#

package (folder) and module names (files) should be lower case

#

@tidal kiln I wouldn't bother having properties for one wire address

idle owl
#

@tulip sleet Nice with the package, I'll try to check it out on my windows machine. I switched to PyCharm and am primarily on my Mac anyway. So I haven't done anything with Windows in a while.

tidal kiln
#

@slender iron then how to access?

slender iron
#

I was thinking just set them directly self.rom = rom

#

but now that I look closer I'd just save _rom and make the other properties return the value from rom

#

so

#
@property
def crc(self):
    return self._rom[7]
tidal kiln
#

but data encapsulation and all that

#

yeah. i like that.

slender iron
#

I'm not sure what you mean by data encapsulation

#

I think it'd be ok if rom was writeable if th erest were dependent on it

tidal kiln
#

doesn't make sense to change anything after it's instatiated

#

and idea is to pass in rom when creating the object

slender iron
#

Β―_(ツ)_/Β―

#

ok

tidal kiln
#

but also, as you can see, there's not much to it, kind of why i was starting to question if it's even needed

slender iron
#

can we consolidate writebit, writebyte and write together?

#

I think its fine

#

it'll make code read better

tidal kiln
#

yeah, but there ends up being only a few places where you use something other than the full rom

#

the family code check is about it

slender iron
#

thats ok

tidal kiln
#

consolidation, and even location, of the read/writes functions is up for discussion

#

i kind of wanted to have all that be in the device class

#

instead of bus class

slender iron
#

but _search_rom uses them

tidal kiln
#

mmm. good point.

slender iron
#

I'd advocate for readinto and write only being public but its not clear to me when individually bit writing is needed in drivers

tidal kiln
#

look at wait_for_convert

#

specific to ds18x20, but could be something similar in other devices

#

just keep reading a single bit to check for when conversion is complete

slender iron
#

no reason you couldn't just read a byte

#

slightly slower but one less api

#

still better than redoing the select

tidal kiln
#

this is the only 1w device i've

#

...worked with

slender iron
#

looks like there are a couple others in the store

#

MAX31850K

#

DS2413

tidal kiln
#

wonder if other's might have some single bit dance needed for something?

#

yeah, should get those, and also multiple of same to test individual addressing

slender iron
#

we can always add it later if we need it

tidal kiln
#

you mean make them private now, but change later if it comes up?

slender iron
#

yup

tidal kiln
#

ok, can try re-working with only having readinto and write available, and _ the others

slender iron
#

thanks! overall it looks good!

tidal kiln
#

cool. i kind of feel like it might be a bit of a mess, with stuff spread out too much maybe. but we'll see what happens...

#

should i still hold off on cookiecutter? (i was starting the apds9960 lib)

slender iron
#

redo it now and you should be good to go

manic glacierBOT
slender iron
#

@tidal kiln it doesn

#

't feel too spread out to me

#

I like that it matches the other classes

tidal kiln
#

github_user = ??

#

assume that's just my account?

#

hmm. it' s more chatty now.

tawny creek
#

@wraith tiger I have some experience tinkering around with both, hmu with any questions

tidal kiln
#

@slender iron still puts in dependency, was the change to allow for saying 'no' ?

slender iron
#

nope, it has the same problem

#

the change mostly to configure it for autobuilding the release zip files

#

I documented the prompts πŸ˜ƒ

tidal kiln
#

nice

#

also just ran cookiecutter and gave it FOOBLAH values for inputs then grepped the results

slender iron
#

?

tidal kiln
#

just a way to see where all the input values ended up

#

grep FOO * in resulting directory

slender iron
#

it does capitalization changes

tidal kiln
#

oh

slender iron
#

so look case insensitively

tidal kiln
#

man grep

slender iron
#

or look in the repo

tidal kiln
#

indeed, much more with -i

timber mango
#

I think an earlier CircuitPython M0 target stamp was released that did not have python code the end-user could modify themselves, for a pre-loaded demo (colour swirls).
The newer one (trinket M0) seems to have modifyable code loaded in it (seems to be something that could be archived to disk, and reinstated, later).
Do I have that right? I want to use the Arduino system for immediate work with the trinket M0, but I want to easily get back to factory conditions (so that I can think about the trinket M0 in terms of how a brand-new user sees it, as shipped).

tulip sleet
#

@timber mango after using it with Arduino, you just need to reload it with the circuitpython .uf2.

#

Another thing you can do is to double-click and copy CURRENT.UF2 out of the TRINKETBOOT drive. That includes everything, including the CIRCUITPY filesystem.

unique turret
#

Question for @twin mica and @fast wharf , I connected a switch to GND and EN on my Feather MO Express project as you did in your CircuitPython painter. Do I need to write any code for that?

timber mango
#

aha. Yeah I have never archived a CURRENT.uf2. Thanks! I think that answers it, other than "Didn't it used to be true that the stamp shipped without end-user access to this stuff?"

tulip sleet
#

@timber mango (Copying CURRENT.UF2 only includes CIRCUITPY on boards without a separate SPI flash chip. So that doesn't work on Circuit Playground Express, etc.)

timber mango
#

Very familiar with going between all three environments (Microsoft, CircuitPython, Aduino) on the Feather M0 Express.

tulip sleet
#

I believe the Trinket and Gemma ship with regular CircuitPython test programs installed. They would be in main.py or code.py. The CPX ships with a MakeCode demo that is not CircuitPython-based.

timber mango
#

Okay, if the CPX doesn't have external SPI flashROM that's probably what was bugging me all along. I can't keep them all straight, one to the next (I have all of them).

tulip sleet
#

The CPX does have a separate SPI flash chip, same chip as on Feather M0 Express and Metro M0 Express.

#

If there's an 8-legged chip on the board, that's the SPI flash.

#

SPIder flash πŸ•·

timber mango
#

Is there any M0 SAMD21 (E18 or G18) in current production at Adafruit that cannot be restored by the end-user to factory setup?

tulip sleet
#

No, though I don't know offhand where the MakeCode demo is for CPX.

timber mango
#

For example, playing with it loading several different environments, sequentially, then restoring it to absolute factory software. As when gifting it to an absolute beginner.

tulip sleet
#

You'll want to upgrade to the latest version of CircuitPython and libraries anyway.

timber mango
#

Right. This is my one chance to see the device as if shipped new to me, so I want to remember what it can do and so forth. I have restored CircuitPython after using the Microsoft ("Make?") and after using Arduino on it (my mainstay).

tulip sleet
#

so if you want to gift an express board, copy CURRENT.UF2 and CIRCUITPY. If non-Express, CURRENT.UF2 is sufficient. If CPX, CURRENT.UF2 is the Makecode demo.

timber mango
#

One of my goals is to keep aware of how the newcomer sees these devices.

#

OKAY. That helps a lot.

#

You get what I'm after -- I probably wanted to have the CPX Makecode demo, and found I could not do so, after Arduino-deputizing the M0.

#

There was a gap somewhere, which is the only reason I'm asking.

#

One other quick question: made in China? My new CPX is marked as that.

#

(just curious)

tulip sleet
#

CPX is very popular and some places are making bulk orders; we didn't have the production capacity for that; we try to make stuff in-house.

timber mango
#

Sure, makes sense. Just wondered as made in NYC seems to be a point of pride.

#

Thanks for your help, @tulip sleet . Very much appreciated by me.

tulip sleet
#

yw! wish I could drop the makecode demo to you. I thought I had an unopened CPX, but apparently not.

#

@timber mango Aha, I do have one. Here's the demo. Note that when this is running, you single-click to get to CPLAYBOOT, not double-click

timber mango
#

That's a beautiful thing. It's looking at me, right now. Made an interesting noise.

idle owl
#

@tulip sleet You have just made the day of SO many people. That's asked after constantly.

tulip sleet
#

It should go in the Downloads section of the CPX Learn Guide.

idle owl
#

That's why I tried to recreate it in CircuitPython. Can't quite get the tones right since cpx plays tones not the same type of beeps as in the MakeCode Demo.

#

@tulip sleet Turns out I can take care of that!

tulip sleet
#

great - that section is a draft, just needs to be published after you put it in. I guess put it in the Learn Guides repo

idle owl
#

Oh I hadn't thought about that. I was going to just upload the file.

tulip sleet
#

could do that too

tidal kiln
#

do that

tulip sleet
#

gotta step out for a while

idle owl
#

Ok

#

@tulip sleet Have a good one

opaque patrol
#

I picked up an feather m0 adalogger and followed the instructions to download bossac and flash the .bin file. It works but only 47kb of free space? Is that correct?

slender iron
#

@opaque patrol yeah because the total file system is 64k. it should be enough to load the SD card drivers though

opaque patrol
#

yeah, I was spoiled by the 2mb on the cpx

slender iron
#

yeah, the adalogger doesn't have the external spi flash

#

😬 49 out of 55 repos need work.

tulip sleet
#

oy

slender iron
#

its easy work though πŸ˜ƒ

#

getting the build configured right

#

and it tells me what needs what

tulip sleet
#

could you work inside the Bundle repo? Maybe you are. Since it has everything as submodules, they're all handy.

idle owl
#

Where does that stat come from @slender iron?

tidal kiln
#

anyone a read the docs guru? having issues with connecting github/rtd.

idle owl
#

pfft. I don't think a RTD guru exists. It's all magic and mystery. πŸ˜›

#

Seriously though, I've never dealt with connecting them. All of the RTD changes I've made were to existing repos.

tidal kiln
#

i've added ReadTheDocs service on the github repo.
i've manually installed repo on Read The Docs.
RTD says "no valid webhook set up" and won't update when repo is changed

idle owl
#

Hmm. And there's nothing about extra things needing to be changed on GitHub?

tidal kiln
#

it's confusing, as github has both a "Webhooks" and an "Integration & services" section for repos

idle owl
#

That is confusing

tidal kiln
#

i'm assuming the "Integration & services" is various pre-configured integrations, including one that use webhooks

#

and "Webhooks" is just a general purpose / manual set up

idle owl
#

Seems like a valid assessment

#

On both counts

tidal kiln
#

but bob refuses to be my uncle ☹

idle owl
#

And the quickstart says go to "Web Hooks & Services" which really doesn't help.

tidal kiln
#

indeed

#

a mashup of the two

idle owl
#

Yeah. Oi

#

Did you even find the RTD built in setting in GitHub?

#

Or did you have to create it manually

tidal kiln
#

it's there, on github, under "Integrations..."

idle owl
#

Ok

#

And it had an "Active" checkbox somewhere?

tidal kiln
#

yep

idle owl
#

I realise you can read and there's literally 8 steps to this, but I've missed instructions in less before.

tidal kiln
#

and a button "Update service"

idle owl
#

Hmm. I feel like something is missing from that list of instructions considering all the menus and buttons have slightly different names now...

#

Like maybe GitHub changed something little up somewhere.

tidal kiln
#

yah, that's what it feels like

#

some under the hood changes, by one or both sides, and the plumbing is all broken

idle owl
#

Exactly

tidal kiln
#

(β•―Β°β–‘Β°οΌ‰β•―οΈ΅ ┻━┻

idle owl
#

That's how I feel when dealing with RTD in general. Well that and Sphinx.

#

Is Sphinx at fault? or is that a different feature entirely.

tidal kiln
#

it's part of the process, but don't think has anything to do with the webhook part of it

idle owl
#

Yeah that seems unlikely

tidal kiln
#

rst -> docutils -> sphinx -> readthedocs

idle owl
#

And of course there's no troubleshooting stuff on RTD 😠

tidal kiln
#

those are the layers of the onion

idle owl
#

Good to know

tidal kiln
#

and i think the outer most one is whats broken

#

github <-> rtd

idle owl
#

Yeah

tidal kiln
#

which would then kick rtd to run sphinx, etc.

wraith tiger
#

Well, I got them breadboarded and the joy featherwing test code working.

tidal kiln
#

@wraith tiger nice

#

what kind of fun happened to the jst connector?

wraith tiger
#

I didn't have enought light on the subject while soldering and didn't realize how close the iron was getting to the jst connector, so it's a little worse for the wear. Dooh!

#

I'm seeing joystick positioning numbers show up randomly in the REPL when I'm not touching it.

idle owl
#

Hmm. I've never worked with it. Sounds like a sensitivity or threshold issue but that's just guessing based on general ideas.

stuck elbow
#

@wraith tiger how did you solve the the problem of missed button presses? are you using the interrupts somehow?

wraith tiger
#

I'm just running the exmple code from the guide so far.

stuck elbow
#

oh, I see

tidal kiln
#

@wraith tiger in this line:

if  (abs(x - last_x) > 3) or (abs(y - last_y) > 3):

increase 3 to a higher number

idle owl
#

@tidal kiln Owait, I was right?

tidal kiln
#

prolly. i haven't worked with it yet either. but it's just an analog read, so...

idle owl
#

Huh. Nice.

tidal kiln
#

@wraith tiger to get a sense of how high it should be, just look at the delta between two succesive prints when you are not touching the joystick

wraith tiger
#

There's jitter in the horizontal from about 518 to 524 and vertical from about 482 to 494.

tidal kiln
#

way bigger than 3

wraith tiger
#

Oddly, though, physically shaking the unit doesn't seem to trigger it.

tidal kiln
#

makes some sense. it's just electrical noise. not related to any physical displacement of the joystick.

#

for example, try changing that line to this:

if  (abs(x - last_x) > 15) or (abs(y - last_y) > 15):
timber mango
#

Try a few breadboard sockets to see if the jitter is less -- the DC connections of breadboards are sketchy at best. Maybe an 0.1uF cap sprinkled like paprika over anything you suspect may help.

#

My tutor used to talk about 'oversampling' the ADC to get more resolution out of it. /not quite relevant here

wraith tiger
#

I added a J_F_F (jitter fudge factor) constant to adjust the tolerance.

timber mango
#

Time domain vs amplitude domain may obtain.

#

"If you see me operating the joystick actively, as evidenced by wild swings, pay a bit more attention and deliver additional accuracy."

#

The 15 vs 3 may be chunkier in response. AT some point it should feel wrong to the human ("this isn't responsive, then gives too much").

wraith tiger
#

My solder joints on SCL and SDA are a bit janky on the Feather. I'll have to touch them up.

timber mango
#

Pullups on SDA and SCL.

tidal kiln
#

@timber mango they're on the joywing already

timber mango
#

May be able to bias the joy to read slightly off-center on a quieter section of substrate, esp. after the center wears (unless it's optical).

stuck elbow
#

it's a pot

#

simple mechanical thing

#

I disassembled a bunch of very similar ones (only smd, not tht)

tidal kiln
#

@wraith tiger a better approach would be to filter the analog readings from the joystick, the current example codes does nothing except a simple threshold

stuck elbow
#

no idea why Adafruit went with THT here

#

the smd ones are also flatter

tidal kiln
ruby lake
#

an old but reliable analog input smoothing line would be something like x += (input.value - x) >> 2

stuck elbow
#

not >>1 ?

#

why are you dividing by 4?

ruby lake
#

by 4 gives you 75% estimated, 25% new value

stuck elbow
#

this is basically: x = x/3 + input.value/4

#

ah, so AB filter

#

x = 3*x/4 + input.value/4, sorry

ruby lake
timber lion
#

@tidal kiln hey yeah i'm around but FYI that code is still being worked on, it's not done until the guide is published

#

it's working so far though but just a warning not totally sure it will work right now πŸ˜ƒ

tidal kiln
#

i'm mainly just curious about the class level buffer. do you consider that an in-work feature?

timber lion
#

oh gotcha, yeah it's probably going to stay for now.. basically i want to reduce the need to create tuples

#

or other bytearray buffers

#

when using the SPI and I2C reads and writes they need to take in a buffer

#

but every time you do
foo = bytearray(x)
it's allocating a new byte array

#

same thing for tuples, like returning (x, y z)

#

in a tight loop like in user code reading acceleration, etc. it can be problematic

#

because each allocate requires new memory, and fetching new memory kicks in the garbage collection etc

#

you get a little perf hit but worse sometimes memory is fragmented and it can't find a large enough contiguous piece of memory to allocate from

#

so it might fail

#

it's rare with the memory we have on the samd21, but definitely can happen

#

it's why all the arduino drivers typically avoid new/malloc too

#

so i try to be strict in the drivers and just use one global buffer rather than allocating one each time it's needed

#

it's a trade off though, with a global buffer you can't have code running in parallel or being re-entrant (like multiple threads)

#

since one bit of code might start using the buffer while another is using it too... need locking then

#

which is a whole new world of complexity πŸ˜ƒ

#

for now nothing really supports multiple threads or re-entrant code

#

but in the future it might change and might need to revisit, why i like to explicitly call it out in the driver

#

so it's easy to go back and find where those dependencies exist

#

reducing bytearray usage like that is pretty straight forward with a bytearray buffer at the class level

tidal kiln
#

is this any different than just having something like:

self._buf = bytearray(7)

in __init__?

timber lion
#

tuples are trickier and in some cases i live with creating them

#

since the readability and usability of tuples is easier vs. passing in some buffer and filling it with values

#

ah yeah the big diff is when it's on the class level like i have it there's only ever 1 buffer for every instance of the class

#

they all share the same buffer so it's basically a global variable

#

vs. like what you show it's an instance member so each instance of the class has its own buffer

#

that would totally work too and be thread safe / re-entrant

#

but if you have multiple sensors you have multiple buffers

#

for 7 bytes.. not the end of the world

#

but for bigger buffers could be troublesome

#

so yeah tradeoffs to make

#

no real right or wrong way to do it, just have to choose what priorities to focus on.. reduce allocations for better speed while losing some benefits like multithreading

#

or use a little more memory and be resilient to that

#

what might be confusing is that for whatever reason python has you reference class level variables with self

#

like self._BUFFER

#

just like with instance variables

#

but they're stored in differents places... i think there were a lot of discussions about this in python and no real happy resolution

#

and i think they rather prefer module level globals, like outside the class

tidal kiln
#

i think python.org bought stock in S, E, L, and F keys

timber lion
#

but yeah it's odd πŸ˜ƒ

#

hah trie

#

true

tidal kiln
#

so why'd you go class level vs. instance?

#

since it's a pretty small buffer

timber lion
#

oh just habit, if nothing does multithreading then i figure better to be strict about memory usage

#

every little byte can count sometimes πŸ˜ƒ

#

it also forces you to write the access code to use a preallocated buffer

tidal kiln
#

esp. here with cp

timber lion
#

vs. creating them all the time

tidal kiln
#

access code = ?

timber lion
#

ah all the code that interacts with spi and i2c devices, most drivers have byte read and write functions

#

like read_u8, write_u16 etc

#

those call the spi/i2c readinto and write functions which need a buffer

#

that's where it uses the preallocated one

#

vs creating a new one with bytearray

tidal kiln
#

oh. gotcha. spi/i2c device "access"

#

cool. thanks.

timber lion
#

ah no problem

tidal kiln
#

most of the code i've seen seems to be doing a pretty good job of using pre-allocated buffers, but at the instance level (which is how i've been doing mine as well)

timber lion
#

yeah no harm in doing that i think

timber mango
#

What is a good feather for robotics

tidal kiln
#

@timber mango what kind of robotics? do you want anykind of wireless control?

timber mango
#

Yeah

slender iron
#

@idle owl the stat is from a script adabot will run

#

@tidal kiln what repo are you trying to set up with RTD? I don't think its worth all the griping πŸ˜ƒ

tidal kiln
idle owl
#

@slender iron That's neat

slender iron
#

@tidal kiln looks like I may have broken it

tidal kiln
#

it somehow worked once, when i first set it up for the third time, but not after that.

slender iron
#

looks related to the new stuff I added

tidal kiln
#

and RTD still says there is no valid webhook

idle owl
#

@tidal kiln Wait that's what you're working on? I had some project ideas but no chance at porting it from Arduino myself.

tidal kiln
#

@idle owl just started today. if you're already working it, then no need for me to.

idle owl
#

@tidal kiln I am not working on it, I looked at it and realised I was completely out of my league.

#

@tidal kiln I don't know Arduino at all.

tidal kiln
slender iron
#

looks like its going now

tidal kiln
#

after a full day of messing around

slender iron
#

maybe they just had a minor outage

tidal kiln
#

i had to setup a webhook on the github side, not use the "Integration..." one

slender iron
#

ah, I usually use the integration just fine

#

and trigger the first build myself

tidal kiln
#

it might have to do with not having the accounts linked also?

#

i don't

slender iron
#

maybe

tidal kiln
#

simple as pushing a commit to trigger a rebuild?

slender iron
#

that works or manually through their interface

tidal kiln
#

oh. right. the "Update service" button under settings...hold.

#

github: " Okay, the hook was successfully updated."

slender iron
#

why are you doing that?

tidal kiln
#

won't that effectively make RTD do a build?

slender iron
#

I guess manually through the interface was ambiguous. I meant the "Build a version" dialog in a project over view on the RTD project page

tidal kiln
#

ah

#

that "their"

#

done. failed same.

slender iron
#

yeah, I'm fixing it

tidal kiln
slender iron
#

@tidal kiln under admin > advanced settings select python 3.x at the bottom

#

on RTD

tidal kiln
#

done

slender iron
#

I believe that triggers a rebuild and it should work

tidal kiln
#

it did. and it does.

#

and makes sense

slender iron
#

looks like I can add something to readthedocs.yml to do it too

tidal kiln
#

what about on RTD under Admin -> Intergrations
should anything be added there?

slender iron
#

no, I add the integration on the github side

tidal kiln
#

that part still doesn't work. just did a quick commit to repo. nothing on RTD.

slender iron
#

which repo are you trying with?

tidal kiln
#

@idle owl so you're not working on driver, just want one for projects?

slender iron
#

I can't see your settings on either side

#

adding the readthedocs integration on the github side should be enough

tidal kiln
slender iron
#

my github account is connected to my RTD

tidal kiln
#

that seems to be the main difference

idle owl
#

@tidal kiln Correct. I thought about trying to work on it since there wasn't one, but it's way outside my knowledge.

tidal kiln
#

@idle owl ok. stay tuned then, i guess.

slender iron
#

and I do see something listed under the RTD integrations tab

idle owl
#

@tidal kiln Will do

tidal kiln
slender iron
#

right, I do have something listed there

#

maybe its added automatically because my accounts are linked

tidal kiln
#

"Github incoming webhook" ?

slender iron
#

yup

tidal kiln
#

i think i tried adding that earlier and it still didn't work. let me try again. maybe it was the cpython2.x thing getting in the way...

slender iron
#

what do you mean add it?

#

it was auto added for me

tidal kiln
#

that's a drop down, can't screen grab it easily, goes away when focus changes

#

where it says "No integrations are currently configured"

slender iron
#

ah

#

I can't help you with that. why not link your accounts and re-add the integration from github?

tidal kiln
#

guess i could, but nothing says thats necessary to get things to work

#

just makes it easier to config

slender iron
#

docs aren't always complete or correct πŸ˜ƒ

tidal kiln
slender iron
#

yes of course

#

nobody is perfect

tidal kiln
#

on the github side, you just have the entry under Integrations? nothing in Webhooks?

slender iron
#

correct

opaque patrol
#

I am having trouble reading the sd card. The only library bundle I could find for download was the latest build...

#
raceback (most recent call last):
  File "code.py", line 8, in <module>
  File "/home/travis/build/adafruit/Adafruit_CircuitPython_Bundle/libraries/drivers/sdcard/adafruit_sdcard.py", line 75, in __init__
  File "/home/travis/build/adafruit/Adafruit_CircuitPython_Bundle/libraries/helpers/bus_device/adafruit_bus_device/spi_device.py", line 61, in __init__
AttributeError: 'Pin' object has no attribute 'switch_to_output'
#

Should /home/travis be in the path?

slender iron
#

yeah, the path is included in the mpy when its built

#

pass in digitalio.DigitalInOut instead of pin

tidal kiln
#

@slender iron thanks for the help. feel like this worked first time i went through your guide, but not since then.

slender iron
#

no problem, maybe they changed things

tidal kiln
#

yah. that's what it seems like.

meager fog
#

imma working on a plotter!

pastel panther
#

The plot thickens!

meager fog
#

:>

glacial bronze
#

Plotter? Darn near killed'er!

meager fog
#

so far so good, tomorrow will try integrating it into the mu editor!

sick creek
#

now i started to think if I can integrate mu editor to my iot app as rosie CI is put to nanocontainer and it talk to travis ci so with circuit python where that pi connect so with touchscreen the mu editor would be nice

manic glacierBOT
manic glacierBOT
#

@violentlyhappi If you have drive issues, see this link for how to reset the CIRCUITPY filesystem: https://learn.adafruit.com/adafruit-circuit-playground-express/troubleshooting#circuitpy-drive-issues

These GitHub issues are more for bugs and feature requests. For support, post in the support forums: https://forums.adafruit.com, or see the #circuitpython channel on our chat server: https://adafru.it/discord.

hollow tartan
#

Have you all heard that the Python beater has been born? It is called Mongoose! Can CircuitMongoose be far behind? LOL πŸ˜ƒ

meager fog
#

@slender iron some plotzing occuring

#

not totally working yet but just needs a lil buffering

#

will keep hackin' till it mostly-works

torn grail
#

Any idea when RFM69 might be supported on Feather M0 in MicroPython?

signal root
#

I copied the Circuit Python uf2 over to my Express playground...how do I go back to MakeCode?

#

I tried copying the UF2 from makecode but it looks circuit python has a hold on the board πŸ˜ƒ

timber mango
#

It should work.

signal root
#

I still keep getting the circuit python repl

timber mango
#

That would be circuit python, yes. πŸ˜‰

signal root
#

so it's definately circuit python still running

timber mango
#

No question on that.

signal root
#

does the UF2 need to be in all caps?

#

or anything like that?

timber mango
#

Ordinarily one might drag and drop it, obviating the need to differentiate that. πŸ˜‰

#

It's going to be the exact same case, always.

#

Filenames and paths are case-sensitive.

signal root
#

Copying to D:

#

All I have is a boot_out.txt

#

and CPX file

idle owl
#

Are you double-tapping the reset button to get to the bootloader?

signal root
#

No!

#

Doh

idle owl
#

The lights on the board should all flash red and then green, and you should see a drive called CPLAYBOOT. That's what you copy a .uf2 file to when you want to load it.

signal root
#

Now I feel silly

idle owl
#

Don't! It's a new thing!

#

FYI, when it's running MakeCode, it's a single tap of the reset button to get to the bootloader.

#

And you'll do that when you want to load a new MakeCode file.

#

If CircuitPython is installed, double-tap.

signal root
#

Ohhhh

#

Good to know πŸ˜ƒ

#

I am digging around pxt code and circuit python - I am seeing what it takes to build a runtime for these baords πŸ˜ƒ UF2 seems a nice way to go

idle owl
#

UF2 is pretty great

signal root
#

so if I drag any UF2 to the board, the board will reset with that binary running

#

So the "CURRENT.UF2" is the firmware that's running

#

In the case of circuit python it has it's own file system

idle owl
#

The CURRENT.UF2 is the entire file system

signal root
#

then double reset to flash

#

Up to the 512

idle owl
#

If I understand your statements correctly, yes

#

But I think that both systems use some of that space, that some of it is allocated

#

so I don't think it's that full amount. I don't know the exact numbers though.

signal root
#

Right

#

Probably half of it is for doing this dance

#

Fantastic πŸ˜ƒ

#

I think I have a lot clearer picture now πŸ˜ƒ

idle owl
#

That's great!

signal root
#

I ordered these M0 boards a while ago - just got around to playing with them

#

Very excited

idle owl
#

Congrats!

timber mango
#

It's a good system and rather complete.

signal root
#

So, I could use platform io to build binaries, then convert to UF2 and bam!?

idle owl
#

@signal root I don't know platform io, so I'm not sure.

signal root
#

OK - I'll give it a shot πŸ˜ƒ

#

And I'll let you know πŸ˜ƒ

idle owl
#

Please do!

#

I'm sure there's others who would know, but sometimes it's rather quiet here over the weekend.

timber mango
#

https://github.com/Microsoft/uf2

as well as

https://learn.adafruit.com/adafruit-feather-m0-express-designed-for-circuit-python-circuitpython/uf2-bootloader-details

---quote---

Making your own UF2 is easy! All you need is a .bin file of a program you wish to flash and the Python conversion script.

https://github.com/Microsoft/uf2/blob/master/utils/uf2conv.py

Get running faster than ever with the first Adafruit Express board

#

I would hasten to add that like a parrot I can speak it but I do not know what it means, with little experience to draw on. On the other hand, I did the vagrant thing and built my own flavor of Circuit Python (99.5 percent identical to what was there already).

#

So it is instructive to build Circuit Python from source inside the virtual machine that vagrant instantiates or mediates (not sure its exact role).

signal root
#

Platform IO seems to be a good way for trageting several boards for the same embedded project. That's being said, I've had limited sucesses using it to run on the ESP8266. With M0's being used in many boardsI'm excited to see if I can get a javascript interpreter like JerryScript or Duktape running on them

timber mango
#

I think that's the older guide for building micropython (circuit python as well).

#

It's the only system I've personally built that outputs to .UF2 for a drag-and-drop firmware update of the Adafruit M0 boards.

#

So everything needed is found while building CircuitPython (the principles involved I mean; it's a complete and working example of this).

signal root
#

I just built a blink hello world in platform.io and converted it to uf2 from the converter script from the microsoft repo

timber mango
#

!

slender iron
#

Plotter looks great @meager fog !

manic glacierBOT
manic glacierBOT
raven canopy
#

in #help-with-projects, @cunning crypt mentioned CP doesn't support multithreading. Instead of asking over there, I figured here would be a better place. I haven't dipped into CP or MP yet, but I might give it a go on the next project. Does MP support multithreading, and is it a planned feature in CP?

cunning crypt
#

@raven canopy I don't belive either the M0 or M4 are capable of multithreading

raven canopy
#

ahh. well, that would be a good reason not to plan for it or attempt it. πŸ˜„

cunning crypt
#

I'm sure there are ways to do software multithreading but.... Honestly, it'd probably slow the device to a crawl

slender iron
#

@raven canopy micropython does have some threading support but its untested in circuitpython. its not a high priority for us due to its complexity

torn grail
#

If I'm using a Feather 8266 and trying to drive a 7segment display, should I be using Micropython or CircuitPython? I seem to be stuck getting MP to work with the 7Segement libraries, and maybe more luck with CircuitPython??

raven canopy
#

@slender iron cool. Thanks for the info.

slender iron
#

@torn grail either should work. Just make sure the library matches the core implementation you are using. IE only circuitpython libraries work with circuitpython

torn grail
#

I pulled the MP libraries for matrix, but can't seem to get the 7segment to load right

#

doesn't appear to be the docs on 7seg, as there are for matirx.

#

import ht16k33_seg

#

display = ht16k33_seg.Seg7x4(i2c, address=0x74)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "ht16k33_matrix.py", line 18, in init
AttributeError: 'Seg7x4' object has no attribute 'WIDTH'

slender iron
#

@stuck elbow may be able to help with micropython

#

otherwise try circuitpython

torn grail
#

Yeah -- thats matix, not 7segment

#

oh, there's segments

#

I'll do some more reading. Thanks @slender iron

slender iron
#

πŸ‘

stuck elbow
#

@torn grail you might have found a bug

#

@torn grail yup, I ported the matrix part to use framebuffer and forgot that the 7seg part uses it too

#

and my "I" I of course mean a friend who made a pull request

#

So I have this CircuitPlayground Expresss Developer Editior thingy, and it doesn't have UF2 bootloader on it. I'm trying to flash circuitpython with bossac on it. Double-clicking the reset gives me a pulsing red led, and then:

BOSSA-adafruit_17_10_19/bin$ ./bossac -e -w -v -R ~/Downloads/adafruit-circuitpython-circuitplayground_express-20171203-b31c2ea.bin 

SAM-BA operation failed
#

What am I doing wrong?

torn grail
#

@stuck elbow , so its bug that seven segment isn't there? I thought it was just me.

stuck elbow
#

@torn grail it's a bug

#

@torn grail working on it now

#

@torn grail do you want to test?

torn grail
#

Good, because I thought I was losing my mind!! (do I get a t-shirt?) LOL

#

I'd love to test. Let me know when to check it out again

stuck elbow
torn grail
#

just downloaded it. now I gotta ampy and then I'll test it out

#

@stuck elbow -- nope

#

display = ht16k33_seg.Seg7x4(i2c, address=0x74)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "ht16k33_matrix.py", line 18, in init
File "ht16k33_matrix.py", line 24, in _write_cmd
OSError: [Errno 19] ENODEV

#

(is there a way to make a code block in discord...)

stuck elbow
#

yes, use \n code\n

#

argh

#

use:

```
your code
```
torn grail
#
display = ht16k33_seg.Seg7x4(i2c, address=0x74)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ht16k33_matrix.py", line 18, in __init__
  File "ht16k33_matrix.py", line 24, in _write_cmd
OSError: [Errno 19] ENODEV

#

yay

stuck elbow
#

hmm, that looks like your device is not connected?

#

does i2c.scan() show it?

torn grail
#

it shows three of them [112, 113, 114] becuase I have them at 0x70, 0x71, 0x72

stuck elbow
#

but not on 0x74?

torn grail
#

oh, whoops -- typo

#

Ah,, yes. Much better!

#

Thanks for "live" code fix, @stuck elbow

stuck elbow
#

thanks for finding the bug, we didn't test that part of the code

#

so I'm making a pull request to the adafruit's repo

torn grail
#

I always find broken stuff. Thats my job!! But usually its in Java. So, I'm branching out.

stuck elbow
#

Ouch, java

#

but at least we have it now tested by a professional tester πŸ˜ƒ

#

let me know if you find any other problems

torn grail
#

I'm starting to port most of my old Ardino code to MP or CP, so I'll be testing out a lot of stuff!!

#

If anyone starts work on porting RFM69, I'd love to test that out. I have a project using it right now.

stuck elbow
#

I got those modules with the mind to write that library over a year ago

#

never got to it

#

it's just too complicated β€” it doesn't help that I never used the Arduino libraries either

torn grail
#

If there is anything I can do to help, let me know

stuck elbow
#

I guess I just need to start building something that uses it

#

and then I will need it

#

got the NRF21L01+ one working, though

torn grail
#

btw -- back to seven seg...

#
display = ht16k33_seg.Seg7x4(i2c, address=0x70)
display2 = ht16k33_seg.Seg7x4(i2c, address=0x71)
display3 = ht16k33_seg.Seg7x4(i2c, address=0x72)
#

that should work to define three different displays, right?

stuck elbow
#

yes

torn grail
#

The first works, but the second two are giberish on the display

stuck elbow
#

that is strange, because they don't share any state

#

do you also get gibberish if you have only one, but not on the default address?

torn grail
#
>>> display.fill(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Seg7x4' object has no attribute 'fill'
stuck elbow
#

well, yeah, no fill

#

it's not a matrix

torn grail
#

Phil would be said if there was no fill. LOL

stuck elbow
#

hmm, I might need to add that fill, actually

torn grail
#

there it goes

stuck elbow
#

I'm using it in the 14seg display code

torn grail
#

took out the fil command, now its hapier

timber mango
#

@stuck elbow I don't know how to simulate your initial conditions -- the .UF2 ships installed and I don't know how you got to the state where there isn't one present.

stuck elbow
#

@timber mango no worries

#

I guess I need to compile and flash the bootloader with the jlink

timber mango
#

/home/nisnis/.arduino15/packages/arduino/tools/bossac/1.7.0/bossac -i -d --port=ttyACM0 -U true -i -e -w -v /tmp/arduino_build_837207/thisprogram.ino.bin -R

#

That's the command line Arduino IDE used.

worn birch
#

oh gosh ... just got the You are running in safe mode... speel ... hmm ... no traceback info... is that stored somewhere after one of these something really bad happened. events?

stuck elbow
#
BOSSA-1.8/bin$ ./bossac -i -d -e -w -v -R ~/dev/circuitpython/uf2-samd/build/circuitplay_m0/bootloader.bin 
Set binary mode
version()=Adafruit CircuitPython 0.8.3-1-gefc15375-dirty on 2017-01-18; Adafruit Circuit Playground M0 (Experimental) with samd21g18
Connected at 921600 baud
readWord(addr=0)=0x30303077
readWord(addr=0xe000ed00)=0x30303030
readWord(addr=0x400e0740)=0x23342c30
readWord(addr=0x400e0744)=0x30304577

Device unsupported
timber mango
#

I will try it on mine.

stuck elbow
#

same with BOSSA-adafruit_17_10_19

idle owl
#

@worn birch Revert your code to whatever previous state, or backup and remove the code you're working on. Then reset the board.

opaque patrol
#

@stuck elbow is it possibly a circuit playground classic?

stuck elbow
#

it has a flash chip on it

robust coral
#

QuickQuestion: is there a millis() function on CircuitPython? Where? I'm using a CircuitPlayGroundExpress and can't find it.

idle owl
#

@worn birch Every time I've run into it, it's been due to a change in my code that failed. I don't think traceback is stored anywhere.

stuck elbow
#

and says 'express' on the back

idle owl
#

@robust coral time.sleep(seconds)

stuck elbow
#

@edgy hatch there is time.monotonic()

idle owl
#

And that

robust coral
#

@idle owl: not sleep, just need to know the time

opaque patrol
#

@stuck elbow okay, its an express....I always check the simple things first

torn grail
#

I'm time.sleeping(500) right now, cuz I forgot it was seconds, not microseconds! LOL

idle owl
#

time.monotonic() is will give you that but it's relative, to when the board started I believe. So you can compare it to itself and subtract to get a period of time if that's what you're looking for.

robust coral
#

that's what I need. Will try Thx

timber mango
#

@stuck elbow Mine does the same as yours. Not broken! Arduino is using some secret sauce.

ard $ /home/nisnis/.arduino15/packages/arduino/tools/bossac/1.7.0/bossac -i -d --port=/dev/ttyACM0 -U true -i -e -w -v /home/nisnis/Downloads/CPX-MakeCode-demo.UF2 -R Set binary mode readWord(addr=0)=0x30303077 readWord(addr=0xe000ed00)=0x30303030 readWord(addr=0x400e0740)=0x23342c30 version()=wE000ED00,4#w400E0740,4#V# chipId=0x23342c30 Unsupported processor Send auto-baud Set binary mode readWord(addr=0)=0x30303077 readWord(addr=0xe000ed00)=0x30303030 readWord(addr=0x400e0740)=0x23342c30 version()=wE000ED00,4#w400E0740,4#V# chipId=0x23342c30 Unsupported processor No device found on /dev/ttyACM0 ard $

stuck elbow
#

time for AdaLink then

#

the nuclear option

opaque patrol
#

@stuck elbow I think it isn't going into bootloader mode.when you double click the reset button, all neopixels should turn green

idle owl
#

@stuck elbow You ordered a Circuit Playground Express and it shipped without UF2 bootloader installed?

stuck elbow
#

@idle owl I got it before it was on sale

idle owl
#

Oooh.. ok. I was incredibly confused.

stuck elbow
#

for testing

idle owl
#

I was going to say regardless of the fact that you have the tools to fix it, you really need to let support know. But that's a totally different story πŸ˜„

stuck elbow
#

it has some differences, for example a transistor in place of the audio amplifier

idle owl
#

I'm on the same page now.

timber mango
#

HEY it looks like I'm in an unusual state! No program is loaded on the CPX now. Will look at it from the host operating system to see what (if anything) is in CURRENT.UF2

#

CPLAYBOOT is still there.

stuck elbow
#

got the bootloader burned \o/

#

the jlink couldn't see it, but my trusty stlinkv2 worked

idle owl
#

@stuck elbow Nice!

timber mango
#

I think my mistake was the file format -- used BOSSAC to do an .UF2 which may be a forbidden combination.

stuck elbow
#

OK, I tried the AudioIO example, and the transistor next to the speaker got hot

#

and I heard nothing and smelled smoke

idle owl
#

BOSSAC won't do UF2 as far as I know.

#

@stuck elbow Oi..

tulip sleet
#

@stuck elbow The UF2 bootloader build also builds a .ino you can compile and load to install UF2. Moot point now. and the smoked transistor: sorry...

timber mango
#

Return the smoke to Adafruit (need an RSA number for that) and they will analyze it for future product development.

stuck elbow
#

I guess that version has the audio circuit organized differently

#

@timber mango this is a product that was never sold anyways

timber mango
#

@tulip sleet How hard is it to get the CPX to a state where there is no bootloader present -- aren't there guards for that? My understanding might be described as "No way the end user is going to need a JTAG connection to revive this target board"

tulip sleet
#

@timber mango the bootloader is protected via the BOOTPROT fuse settings. You'd have to unset those to overwrite the bootloader. Do you think you're in that state? You didn't break anything by loading a UF2 with bossac - it just won't load a usable program.

timber mango
#

No I'm back to the Makecode demo as if nothing had happened. I used the drag and drop interface, as usual, to restore normal operation. Double-checked: Arduino compiles and loads my usual project, no problem, after all that (see scrollback). I could't break it (well, not yet, anyway).

#

Like everyone else I'd like a software kit that lets me break and reload the bootloader, by setting the fuses, via the same USB interface. I can't remember what was said about that, but I thought it was a difficult thing to do (and wouldn't happen by random writes, due to the fuse mechanism being improbably (or impossibly) triggered.

#

In the long run I want to be able to modify the stored program on-device (to augment it). My understanding was that can only be done from behind the 'fence' between low storage memory and high storage memory (my regular 'program' would have to operate in bootloader-space).

#

Well, I do have a working means to store and load the interpreted program on-device (on SPI flashROM) .. to load forth programs, or save them (I can author new forth code on-device for any of the Express series M0 targets, now).

#

However .. the recapitulated code (stored on flashROM) is compiled into the 32k system ram address space, so there is a 32KB limit to the size of a newly-compiled program, plus all the existing stuff that lives there (probably halves the RAM available for compiled code).

#

I would really like to make use of the 256KB on-chip storage. πŸ˜‰

stuck elbow
#

that is way over my head

#

by the way, I wanted to test audio on the CPX because on my own board it's very bad

#

the wav's I'm playing all click and buzz

#

and I was wondering whether the problem is with my circuit or with the software

timber mango
#

The Makecode demo plays a very short sound during boot.

#

But it's an interesting sound. Like a voice in MIDI or something.

stuck elbow
#

I'm generating those wav files with sfxr

idle owl
#

@stuck elbow I have 4 in front of me that play wavs just fine. Could be software?

stuck elbow
#

I suspect they don't begin/end on a neutral position, hence the clicks

robust coral
#

you said "all" click and buzz tho.

stuck elbow
#

I have a video

robust coral
#

is it only at start and end of a sample?

idle owl
#

Hmm, also if the speaker is initialising weird in the code, it'll click when it initialises and when it stops.

torn grail
#

That's awesome!

stuck elbow
#

there is a "pew" sound and an explosion sound, you can hear them behind all the clicks and buzzing

idle owl
#

@stuck elbow That looks great! About the sound though hmm....

timber mango
#

ruminants

stuck elbow
#

I copied the audio circuit from the CPX, but I have a different speaker, because I couldn't find the same

#

I'm really bad at analog circuits

#

some of the buzzing is my finger touching the audio in

#

(I moved the audio circuit out the way in the next version)

timber mango
#

Some audio circuits have what amounts to a squelch. When they gate-on it can be painful to listen to in headphones.

#

(notably most modern 2-way radios have this flaw)

stuck elbow
#

here the amplifier is always on

timber mango
#

You know it's not key-clicks from actuating the 4-way controller?

#

Maybe bridge the momentary switch contacts with a capacitor.

stuck elbow
#

no, the worst clicks are actually at the beginning of the sample

#

probably because the sample doesn't start at 0

#

also, after playing a sample, the circuit will stay buzzing

#

as if the DAC wasn't released

timber mango
#

Sounds like you need a low-level authoring tool for the raw media file. Or a 'blesser' for that kind of media file.

#

Can you obtain a proper file that does work with the rest of the setup the same?

idle owl
#

There are sets of wav files for CPX projects available if you need something to test. But you said it's not quite the same as the CPX, so I'm not sure whether it'll help.

timber mango
#

How long of a media file can the CPX present? Three seconds of clean audio?

manic glacierBOT
worn birch
#

@stuck elbow Sweet ... so small ... looks cool ... can't imagine any teachers are going to be fans though.... but fun none the less!

stuck elbow
#

@worn birch Thanks. I have a more teacher-friendly device, with an 8x8 LED display instead of the LCD.

tulip sleet
#

@timber mango re your earlier message about the bootloader: the bootloader (either arduino-style or UF2) loads a program in to flash, not into ram. That's what you want, right?

idle owl
#

CPX can play wavs for longer than that. The limiting issue is the file size, in my experience anyway.

timber mango
#

@tulip sleet I want to start with an Arduino that presents a text interpreter in the serial USB, that allows compilation into 256KB flashROM space (on-chip storage). I already compile to the 32KB RAM storage space.

#

So I want to write to $4000 not $2000000

#

(never mind how many zeroes hehe)

#

The code fence is near $4000 I think; I'd have to (as I understand it) code for the space below that address, and essentially author a custom bootloader.

#

Because programs running north of that address are not allowed to write to flash.

#

So the work-around people use is to run a very small kernel in bootloader-space that is permitted to write to the rest of the flash space (just as the bootloader has such permission).

stuck elbow
#

that's weird, because the non-express versions of CircuitPython have the filesystem in flash

#

in the on-chip flash, I mean

timber mango
#

Yes there is 256KB of that.

#

Without the SPI flashROM chip (which is an additional 2MB)

#

The thing is, that SPI flashROM isn't addressible (at all). It's a filesystem.

stuck elbow
#

and I don't think they need a special bootloader?

#

well, how do you write to a filesystem if you can't address it?

timber mango
#

Via the SPI bus.

#

It's an SPI device, rather than in the memory map.

stuck elbow
#

to the internal on-chip flash?

timber mango
#

It's a peripheral.

#

The internal flash is in the memory map. It's not a peripheral (per se).

tulip sleet
#

@timber mango I think you may be misinformed. It's perfectly possible for a program not in the bootloader section to write to flash

#

as deshipu mentions, that's how we write to the top 64k of flash to implement in the in-flash filesystem for CircuitPython.

timber mango
#

Okay. I don't understand enough of it to have a lucid comment. I thought this was kind of cast in stone.

tulip sleet
#

not at all. but you have to erase a whole section at a time and then rewrite it. Are you writing your interpreter in Arduino or bare-metal?

timber mango
#

Arduino.

tulip sleet
#

I found a library for 328 flash writing. Will ook for one for SAMD flash writing

timber mango
#

I wasn't even trying because I thought it was impossible. Now that you mention it, main.py has to live somewhere on a non-Express M0 target from af.com

tulip sleet
#

@timber mango iare you wa1tnr? or are you referring to wa1tnr's code as an exmaple?

timber mango
#

I am himself. I have your cmaglie bookmarked since Feb 2017. I wonder why I moved past without looking at it!

tulip sleet
#

cmaglie's code has some functionality to act as an eeprom and write only a small area, but take a look at FlashStorage.cpp and .h for a general interface.

timber mango
#

If I can buffer the segment of the flash to be rewritten I don't care how large the erase is, so long as I can restore the old part to be able to write the new part.

#

But generally, they are tiny writes into SRAM. Just a handful of bytes at a time, as that's how a forth compiles.

tulip sleet
#

I think that's what cmaglie's lib does. You'll want to buffer the writes so you don't rewrite too many times and wear out the flash.

timber mango
#

Yeah I would probably resort either to SRAM or maybe FRAM (external SPI or i2C) for the small incrementals, and then do a write when I was satisfied.

torn grail
#

@stuck elbow -- Back to ht16k33 for a sec. I think I found another bug. When I do a display.number(1111), then display.show(), I see "1110" on the 7-segment display. πŸ˜ƒ

#

strange, 1234 works

stuck elbow
#

I really need to dig out my modules and test this properly

torn grail
#

ugh

#

weird, its 1111 and 1112 that are nutty

stuck elbow
#

I will do that tomorrow, it's past midnight here

torn grail
#

thanks, man. nite nite

stuck elbow
#

just to make sure, display.text('1111') works?

torn grail
#

nope

#

nether does 2222

stuck elbow
#

what do you mean by "nope" exactly? what is shown?

torn grail
#

I'll have to get back in to my test, but I think 2222 displays 2221

#

but 2223 is okay

stuck elbow
#

when you use .text and not .number too?

torn grail
#

I can test with you tomorrow if you want. I'm in California. Pacific time.

#

I'm 7segment, so no alpha. just numbers

stuck elbow
#

I'm in CET, 9h difference

#

sure, but .text will still work with numbers

#

that's what .number uses internally

torn grail
#

I'll try out some more things to see what I can "break"

stuck elbow
#

thanks

sacred blade
#

@stuck elbow it's because of rounding errors with the 30bit floats. "{:f}".format(1111)gives '1110.999941' on a m0 ...

stuck elbow
#

ouch

torn grail
#

Nice!

#

I'm making a bitcoin tracker, so that just cost me $1000 !!

#

lol

stuck elbow
#

I didn't expect to hit that with just 4 digits

#

@torn grail you can use .text and format the number to a string yourself

torn grail
#

I'll try the .text and see how that goes

tulip sleet
#

that looks like a bug; {:f} should do better than that

stuck elbow
#

cpython has some smart rounding on display

torn grail
#
>>> display3.text(str(1111))
>>> display3.show()
#

works fine

tulip sleet
#

yeah but 1111 should fit in 22 bits of mantissa

stuck elbow
#

I think it always picks the shorter representation when there is ambiguity

tulip sleet
#
>>> "{:f}".format(1111)
'1110.999941'
>>> 1111.0
1111.0
#

something is wrong with the arithmetic in format()

stuck elbow
#

@torn grail you really have a talent!

sacred blade
#

Yes, ```

str(1111*1.0)
'1111.0'

So there is indeed something wrong in format...
torn grail
#

That's why the guys at work tell me. :p

#

πŸ˜ƒ

tulip sleet
#

bleah, py/formatfloat.c normalizes the number to be between 1 and 10 by multiplying by 0.1 repeatedly, even for f vs e format. [EDIT: slightly wrong, but close to the problem]

#

then it multiplies it by 10.0 repeatedly as necessary.

stuck elbow
#

0.1 is a great choice πŸ˜„

tulip sleet
#

ugh

stuck elbow
#

having infinite representation in binary an all

tulip sleet
#

i'll see if someone filed an issue on this in MicroPython.

timber mango
#

I managed to not be able to reinstall CircuitPython, by attempting to update /lib which I think must be corrupt (or non-existant). Cannot get a REPL. Arduino works fine; Makecode demo .UF2 uploads and runs fine on CPX. Seems to me the system has retained the wrong things I did to the flashROM where main.py and /lib live.

Was trying to install the bundle,
adafruit-circuitpython-bundle-2.x-20171128.zip

idle owl
timber mango
#

@idle owl thanks

idle owl
#

You should be able to drag the /lib folder to the CIRCUITPY drive to load it when CircuitPython is loaded. It's possible it gave you issues if it reset before it was done copying something.

timber mango
#

It tried to overwrite existing /lib earlier. The flash eraser worked and I probably have a REPL now (can see a drive for the device in the filemanager)

idle owl
#

Excellent

#

When you load a file, the board will soft reboot, which makes sense because that's how it reloads when you update code.py. However, if you're overwriting the existing /lib folder, it could lead to a soft reboot during copying which could have corrupted it.

timber mango
#

Everything looks good now.

idle owl
#

Ok good

timber mango
#

I did not have a /lib this time. That was the problem, a pre-existing /lib

#

REPL is there. But I'm python braindead so I don't know how to test it well.

idle owl
#

I've overwritten an entire /lib folder previously though, and not had it end up corrupted, so it's not a guarantee that it will cause issues. It does, however, increase the likelihood as it may try to reload as each file is finished copying.

timber mango
#

It wanted me to make a decision to replace every file.

idle owl
#

I'm never great with testing in the REPL unless I have code I'm trying to debug. Just to check if it's working, I'll do ```python

import board
dir(board)

timber mango
#

That wasn't flying too well. I must've done something wrong.

idle owl
#

I'm on a different OS, so that could be another reason. You may not have done anything wrong.

#

At least I assume I'm on a different OS. What are you running?

timber mango
#

Debian for the amd 64 on a laptop.

``>>> import board

dir(board)
['A0', 'SPEAKER', 'A1', 'A2', 'A3', 'A4', 'SCL', 'A5', 'SDA', 'A6', 'RX', 'A7', 'TX', 'LIGHT', 'A8', 'TEMPERATURE', 'A9', 'BUTTON_A', 'D4', 'BUTTON_B', 'D5', 'SLIDE_SWITCH', 'D7', 'NEOPIXEL', 'D8', 'D13', 'REMOTEIN', 'IR_RX', 'REMOTEOUT', 'IR_TX', 'IR_PROXIMITY', 'MICROPHONE_CLOCK', 'MICROPHONE_DATA', 'ACCELEROMETER_INTERRUPT', 'ACCELEROMETER_SDA', 'ACCELEROMETER_SCL', 'SPEAKER_ENABLE', 'SCK', 'MOSI', 'MISO', 'FLASH_CS']

``

idle owl
#

Ok Linux is what I figured. I'm running MacOS.

#

Yep, that's all correct!

timber mango
#

So that proves the bundle loaded?

idle owl
#

That's everything you can load out of board when you import it. If you did not already know that.

#

Oh... no

#

Do um... let's see. import adafruit_dotstar

timber mango
#

great. yeah now we're talking.

idle owl
#

Then do a dir(adafruit_dotstar)

timber mango
#

thanks.

idle owl
#

If that doesn't give you a module failure, that lib is loaded correctly, and it's a safe bet the others are too. However, without testing each one, you wouldn't know for certain. It is incredibly likely they rest are fine though.

timber mango
#

``>>> import adafruit_dotstar

dir(adafruit_dotstar)
['time', 'digitalio', 'DotStar', 'busio', 'name']

``

#

No we're just looking for a very basic "yeah it looks like it loaded because dotstar won't be there if it didn't load" kind of confimations.

idle owl
#

Excellent, then that's exactly what you're looking for. It's a simple way to check if a module is present.

#

I get the same thing, I checked. You're good there.

timber mango
#

Thank you. I've rebuilt CircuitPython in vagrant session many times (earlier in the year) but I have no memory of doing much of anything in REPL itself. I modified the REPL to do what I wanted (display status messages upon entry) and maybe something else trival.

#

It's like I never touched it in my life. Effects of aging I suppose.

idle owl
#

Could be. Or it could simply be coming at it from a different angle makes it just enough different to be foreign. For me if it's only a little different, it's far more difficult than if it's completely different.

timber mango
#

high-contrast different. or almost-the-same different.

idle owl
#

When I first started coding, MakeCode was incredibly difficult for me because I knew just enough Python to have the visual codeblocks seem impossible to understand. After a few months, I went back to it when a friend bought a CPX and wanted to start programming, and it made SO much more sense at that point. I'm happy I skipped MakeCode though, it got me right into CircuitPython. But I'm really glad MakeCode exists as it's give my friend a chance to learn so much.

timber mango
#

I found MakeCode to be a fun diversion and a very visual way to learn it, but I didn't spend that much time on it. I do remember editing the source the drag-and-drop interface created, in a regular text editor, once I was able to understand what it was doing.

#

Also I made a local installation so I didn't use the Internet to code in MakeCode, after I understood how to create the same environment, locally.

idle owl
#

Nice

timber mango
#

Adafruit has rolled out CircuitPython so fast that it kind of moots what MakeCode can do for the CPX.

idle owl
#

I disagree. I would have agreed with you before my friend bought hers. We tried a little CircuitPython and she was completely lost. But she's really starting to understand code structure and function using MakeCode.

timber mango
#

Well, one is visual and drag and drop, the other is typing and reading reference literature. πŸ˜‰

idle owl
#

Valid point. But for someone who has literally never programmed anything in her life, MakeCode has been a great resource to get started with.

ruby lake
#

is the simplest way to write 16 bits to an SPI device something like x = bytearray(2) then spi.write(x)

#

assuming of course the SPI is configured

timber mango
#

Any port in a storm. We need more approaches because once people realize how it works it doesn't matter so much what door they walked in, so long as they're now inside.

ruby lake
#

and you give x its actual value

idle owl
#

@timber mango Exactly.

timber mango
#

I need to go soak my head in brine. For a long time. Thank you for your help, @idle owl

idle owl
#

@timber mango You're welcome! I hope you get some good rest

timber mango
#

whoa metro m4 testers whoa. I am going going gone. Goodnight.

idle owl
#

Night!

#

@ruby lake I'm not sure. I wanted you to know you hadn't been lost in the conversation. Late night on weekends can be quiet here. I would suggest asking again tomorrow if you have the option.

ruby lake
#

sure, no rush πŸ˜‰

ruby lake
#

aha, thats how to do it. Enumerate a list of pots to read as pot = [ analogio.AnalogIn(board.A1), analogio.AnalogIn(board.A2), analogio.AnalogIn(board.A3)]

#

then I can loop in pot[i].value

idle owl
#

Nice!

ruby lake
#

is there a time.millis() or similar library call? time.monotonic is not granular enough

idle owl
#

I think there's only time.monotonic().

torn grail
#

Has anyone ever used the hardware timers in MicroPython to trigger functions at a specific interval? Other that PMW...

wraith phoenix
#

Just checking out CircuitPython because I have never programmed in Python before.. . .

idle owl
#

Excellent! Welcome!

wraith phoenix
#

Thanks kattni! Any suggestions on resources to lok at?

#

look at ?

idle owl
#

Ooh. Do you have a particular board you're using?

wraith phoenix
#

Just got a free Trinket M0 w/ my Oct. Adafruit order.

idle owl
wraith phoenix
idle owl
#

Not all of them will work with Trinket, but you might find some good information in other projects as well.

tawny creek
#

welcome @wraith phoenix ! the trinket is awesome πŸ˜ƒ

#

also awesome username xD

wraith phoenix
#

Am getting read to install avr-gcc for linux on my PC to program both an ATMega328p 8-bit micro plus the trinket. What do I need to look for/install from my debian repo's ?

tawny creek
#

it mounts as a usb drive with a file system

wraith phoenix
#

A 32-bit micro the size of my thumb - HA!!!!

tawny creek
#

you dont need anything else other than a text editor πŸ˜„

#

for arduinoo

tulip sleet
wraith phoenix
#

thank you for the URL, kattni. Will look at it tomorrow.

idle owl
#

@wraith phoenix We're here for questions as well! You're welcome!

wraith phoenix
#

Thanks for the URL, cascade. Could be my secret to success πŸ˜ƒ

idle owl
wraith phoenix
#

Thanks so much, kattni. Got your URL too. I t's been a few years since I mucked w/ IRC, so please be patient with me.

idle owl
#

No worries!

wraith phoenix
#

Actually, it's half the size of my thumb πŸ˜ƒ

tawny creek
#

@wraith phoenix πŸ˜„ im excited to build one from scratch when i get the pcb's from osh park

wraith phoenix
#

Rolling your own already ?

tawny creek
#

@wraith phoenix just for practice and experience, i want to design and build my own board eventually :3

wraith phoenix
#

@cascaede Great! I am new to OSHW. But am a longtime linux user.

cunning crypt
#

@idle owl What's involved in writing a Learn article? I feel like my examples would go great alongside an article explaining just what it is that they're doing.

idle owl
#

@cunning crypt Typically they'll have you write up something on Instructables or another site like that to have an idea of your writing. Then you get added to the Learn system, run through the tutorial type thing for it. Once you're in that system you can use other guides to get an idea how they look and flow, and then you write up your own.

#

It's all good. It'll be CP related in the end anyway. πŸ˜‰

cunning crypt
#

Honestly, they'll probably just be able to look at the pile o' comments I'm leaving in this "example"

#

It's basically a page of a learn article by itself

idle owl
#

That's great! But it's still a great idea to consider writing up a guide for it, and your comments will make it easier on you later!

cunning crypt
#

Oh, yeah! I want to write a guide.

#

Basically, this example wouldn't be an example at that point. It's... too flimsy as an actual program. The other examples would each have their page, etc.

idle owl
#

I ended up taking out some of the comments in my code when I put it in the guide because it was too much with all the explanation around it. But I definitely wished I had commented more when I was working on the guide. So you're in a good place.

cunning crypt
#

I learned long ago: Comment the heck out of everything.

#

That way, when you pick up the project in six months, you know what you were thinking

idle owl
#

Exactly!

#

@cunning crypt Mind a DM?

cunning crypt
#

Go ahead

slender iron
#

@wraith phoenix For the Trinket M0 you'll need the arm gcc toolchain not avr

#

@ruby lake what resolution do you need that time.monotonic doesn't have? bytearray is the way to go for 16bits on SPI

ruby lake
#

@slender iron I've set up a variable dacData = bytearray(2) and put my value into it, but the spi.write(dacData) gives an error saying "object requires buffer protocol"

slender iron
#

how did you put your value into it?

#

you'll need to do each byte separately

ruby lake
#

x = (note - 24) * 273 #Magic formula for correct semitone scale (n-t)*4095/60
dacData = bytearray(2)
dacData = (x >> 2) + ((x >> 1) & 1) #Round to nearest int for 0.5 LSB accuracy
dacData |= 0xB000 #channel 2, gain=1x, no vref buffer, output active

#

the SPI write examples don't show working with a variable, only literals

slender iron
#

treat the byte array like you would a list

#

dacData[0] = first byte value

#

dacData[1] = second byte value

#

the second assign is replacing the bytearray with an int

#

its the benefit/problem with python. variables can change type

manic glacierBOT
ruby lake
#

@slender iron ah, so something like dacData[0] = (x & FF00) >> 8