#circuitpython-dev
1 messages Β· Page 128 of 1
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
pick the narrowest namespace scope needed, which is inside the class
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."
i guess the lookup will be faster because you won't have to say self.CONST
inside the class
which is probably more important than the namespace protection? thus the pep8 wording?
ha! has pretty much every possible question been asked on s.o.???
Yeah I'd say so
trying an experiment... hold on..
but has no discussion or mention about your self. point
_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()
whats the better prog pactice argument?
put them in the namespace that uses them
yep
but our code is small, so it's all readable anyway, one way or the other
interstingly, those two examples seem to do the opposite
the one that could be class level is module level
^^ ds18x20.py
while onewire.py hides some globally useful onewire defines in the class
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.
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?
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
but understandable
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
i think you've answered it
also, 99.9% of whats been written is module level
thanks for the input!
yw! (watching a live guitar lesson at same time)
planning to try out for Toolchain Pain?
only acoustic - no heavy metal, more like Python, Paul, and Mary
(took a long time to come up with a mediocre jjoke)
@tulip sleet You're in for Toolchain Pain Unplugged.
@tulip sleet Do I remember right that we have erasers for nonexpress boards?
yes: https://github.com/adafruit/Adafruit_Learning_System_Guides/tree/master/uf2_flash_erasers; also mentioned in the Troubleshooting guide (as revised in master)
wrong, in 2.x Troublshooting: http://circuitpython.readthedocs.io/en/2.x/docs/troubleshooting.html
I'll merge that into master when I do the next update merge from 2.x
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...
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?
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 π¦
@azure wigeon you probably have corrupted the file system. Welcome to the club π you can erase it and start fresh. The instructions are here. https://circuitpython.readthedocs.io/en/latest/docs/troubleshooting.html#file-system-issues
Thanks I'll try that
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 great! If you want to write from CircuitPython, there is a guide. Just need a few minutes to find it.
@azure wigeon found it https://learn.adafruit.com/cpu-temperature-logging-with-circuit-python/writing-to-the-filesystem?view=all
<@&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.
@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
@formal plover Hey Kurt!
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.
from the micropython forums I remember that the mqtt stuff worked pretty well, but I never got into IoT myself
This issue is resolved as of pull request #465, it can be closed.
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.......π
Good problems to have? π
@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.
@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...
@bronze geyser You could check out the forum post and respond there if you have anything to add π
@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.
Getting fancy!
@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...
@bronze geyser And yet you always end up explaining something useful. π
My you are kind @idle owl. Thank you.
@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 π
@idle owl -> again, many thanks.
You're always welcome!
Looks like @tdicola took care of it:
https://github.com/adafruit/Adafruit_CircuitPython_TCS34725
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?
It's likely that the file system is corrupted. Does it show up as FEATHERBOOT if you tap the reset button twice?
IT just came up with "Installing device driver software".
What OS are you currently on?
Windows 7
Did it ever show up on Win7 for you? Or is this your initial attempt to use it.
Threee of the four show up as "Ready to use".
The M0 is still searching Windows update.
Now FEATHERBOOT shows up.
Ok that's good!
All the driver installs competed.
You're trying to work with CircuitPython, correct?
I tried to use it last night and this morning and the block device never showed up.
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?
Yes, I'll try circuit python first but I also updated the Arduino IDE .
Nice!
I've messed about a bit with an Arduino Uno previously.
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
I'm downloading the Feather m0 express uf2 file from github.
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.
OK, done. Now CIRCUITPY shows up.
Nice!
OK, the blinky from the guide appears to be running properly.
That's great! Nice job π
Thanks for your help.
Yeah for sure! You're welcome
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.
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. π
Yeah, I hope to end up with a semi compact device that I'll try to design a case to 3d print for.
Ah then headers will indeed be your friend there.
I'll be experimenting with truning it into a HID.
Oh nice
I'm wondering if it would be possible for one device to be a keyboard and mouse at the same time.
That one I'm not sure about.
Hopefully either that or toggling back and forth in software will work.
Well, I'm off to lunch. Thanks again.
You're welcome! Have a good one!
You'd have to build a custom USB descriptor for a composite device, but it could be done
For example, there's iStickToIt for the Pi 0 http://isticktoit.net/?p=1383
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
<@&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
@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?
@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 yes, with a composite descriptor
@tidal kiln I should switch it to a choice
Neat
ah. the inputs are simple. if input then foo
yeah
the choice option doesn't look much better: https://cookiecutter.readthedocs.io/en/latest/advanced/choice_variables.html
yes and no are both true π
yeah unfortunately
@tidal kiln if you are just cookiecuttering hold off a bit
I have an update PR for it
ok. a few steps in, but not too much if you want me to start over.
@tulip sleet take another look. I added a note about looking it all over
@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.
package (folder) and module names (files) should be lower case
@tidal kiln I wouldn't bother having properties for one wire address
@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.
@slender iron then how to access?
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]
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
doesn't make sense to change anything after it's instatiated
and idea is to pass in rom when creating the object
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
can we consolidate writebit, writebyte and write together?
I think its fine
it'll make code read better
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
thats ok
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
but _search_rom uses them
mmm. good point.
I'd advocate for readinto and write only being public but its not clear to me when individually bit writing is needed in drivers
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
no reason you couldn't just read a byte
slightly slower but one less api
still better than redoing the select
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
we can always add it later if we need it
you mean make them private now, but change later if it comes up?
yup
ok, can try re-working with only having readinto and write available, and _ the others
thanks! overall it looks good!
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)
redo it now and you should be good to go
As we talked about on Discord, it'd be good to:
- [ ] Remove _crc, _family_code and _serial_number from the address class in favor of reading it directly from rom in each property.
- [ ] Only expose write and readinto outside of onewirebus.
@tidal kiln it doesn
't feel too spread out to me
I like that it matches the other classes
@wraith tiger I have some experience tinkering around with both, hmu with any questions
@slender iron still puts in dependency, was the change to allow for saying 'no' ?
nope, it has the same problem
the change mostly to configure it for autobuilding the release zip files
I documented the prompts π
nice
also just ran cookiecutter and gave it FOOBLAH values for inputs then grepped the results
?
just a way to see where all the input values ended up
grep FOO * in resulting directory
it does capitalization changes
oh
so look case insensitively
man grep
or look in the repo
indeed, much more with -i
@slender iron maybe add that link to the prompts here? https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/creating-a-library#cookie-cutter
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).
@timber mango You can copy everything out of the CIRCUITPY drive and save it. There is also a .zip of what it shipped with: https://learn.adafruit.com/adafruit-trinket-m0-circuitpython-arduino/downloads
@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.
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?
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?"
@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.)
Very familiar with going between all three environments (Microsoft, CircuitPython, Aduino) on the Feather M0 Express.
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).
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 π·
Is there any M0 SAMD21 (E18 or G18) in current production at Adafruit that cannot be restored by the end-user to factory setup?
No, though I don't know offhand where the MakeCode demo is for CPX.
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.
You'll want to upgrade to the latest version of CircuitPython and libraries anyway.
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).
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.
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)
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.
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.
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
That's a beautiful thing. It's looking at me, right now. Made an interesting noise.
@tulip sleet You have just made the day of SO many people. That's asked after constantly.
It should go in the Downloads section of the CPX Learn Guide.
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!
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
Oh I hadn't thought about that. I was going to just upload the file.
could do that too
do that
gotta step out for a while
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?
@opaque patrol yeah because the total file system is 64k. it should be enough to load the SD card drivers though
yeah, I was spoiled by the 2mb on the cpx
yeah, the adalogger doesn't have the external spi flash
π¬ 49 out of 55 repos need work.
oy
its easy work though π
getting the build configured right
and it tells me what needs what
could you work inside the Bundle repo? Maybe you are. Since it has everything as submodules, they're all handy.
Where does that stat come from @slender iron?
anyone a read the docs guru? having issues with connecting github/rtd.
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.
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
Hmm. And there's nothing about extra things needing to be changed on GitHub?
it's confusing, as github has both a "Webhooks" and an "Integration & services" section for repos
That is confusing
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
i've pretty much done this:
https://github.com/rtfd/readthedocs.org#quickstart-for-github-hosted-projects
but bob refuses to be my uncle βΉ
And the quickstart says go to "Web Hooks & Services" which really doesn't help.
Yeah. Oi
Did you even find the RTD built in setting in GitHub?
Or did you have to create it manually
it's there, on github, under "Integrations..."
yep
I realise you can read and there's literally 8 steps to this, but I've missed instructions in less before.
and a button "Update service"
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.
yah, that's what it feels like
some under the hood changes, by one or both sides, and the plumbing is all broken
Exactly
(β―Β°β‘Β°οΌβ―οΈ΅ β»ββ»
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.
it's part of the process, but don't think has anything to do with the webhook part of it
Yeah that seems unlikely
rst -> docutils -> sphinx -> readthedocs
And of course there's no troubleshooting stuff on RTD π
those are the layers of the onion
Good to know
Yeah
which would then kick rtd to run sphinx, etc.
Well, I got them breadboarded and the joy featherwing test code working.
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.
Hmm. I've never worked with it. Sounds like a sensitivity or threshold issue but that's just guessing based on general ideas.
@wraith tiger how did you solve the the problem of missed button presses? are you using the interrupts somehow?
I'm just running the exmple code from the guide so far.
oh, I see
@wraith tiger in this line:
if (abs(x - last_x) > 3) or (abs(y - last_y) > 3):
increase 3 to a higher number
@tidal kiln Owait, I was right?
prolly. i haven't worked with it yet either. but it's just an analog read, so...
Huh. Nice.
@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
There's jitter in the horizontal from about 518 to 524 and vertical from about 482 to 494.
way bigger than 3
Oddly, though, physically shaking the unit doesn't seem to trigger it.
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):
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
I added a J_F_F (jitter fudge factor) constant to adjust the tolerance.
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").
My solder joints on SCL and SDA are a bit janky on the Feather. I'll have to touch them up.
Pullups on SDA and SCL.
@timber mango they're on the joywing already
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).
it's a pot
simple mechanical thing
I disassembled a bunch of very similar ones (only smd, not tht)
@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
@timber lion you active? want to ask you about this:
https://github.com/adafruit/Adafruit_CircuitPython_FXAS21002C/blob/master/adafruit_fxas21002c.py#L69
an old but reliable analog input smoothing line would be something like x += (input.value - x) >> 2
by 4 gives you 75% estimated, 25% new value
this is basically: x = x/3 + input.value/4
ah, so AB filter
x = 3*x/4 + input.value/4, sorry
hm, there is a wiki page about it, https://en.wikipedia.org/wiki/Exponential_smoothing
Exponential smoothing is a rule of thumb technique for smoothing time series data. Whereas in the simple moving average the past observations are weighted equally, exponential functions are used to assign exponentially decreasing weights over tim...
@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 π
i'm mainly just curious about the class level buffer. do you consider that an in-work feature?
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
is this any different than just having something like:
self._buf = bytearray(7)
in __init__?
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
i think python.org bought stock in S, E, L, and F keys
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
esp. here with cp
vs. creating them all the time
access code = ?
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
ah no problem
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)
yeah no harm in doing that i think
What is a good feather for robotics
@timber mango what kind of robotics? do you want anykind of wireless control?
Yeah
@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 π
@slender iron repo: https://github.com/caternuson/Adafruit_CircuitPython_APDS9960
rtd: https://readthedocs.org/projects/adafruit-circuitpython-apds9960/
@slender iron That's neat
@tidal kiln looks like I may have broken it
it somehow worked once, when i first set it up for the third time, but not after that.
and RTD still says there is no valid webhook
@tidal kiln Wait that's what you're working on? I had some project ideas but no chance at porting it from Arduino myself.
@idle owl just started today. if you're already working it, then no need for me to.
@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.
@slender iron i had similar grief getting github and RTD hooked up with this:
repo: https://github.com/caternuson/readthefoo
rtd: https://readthedocs.org/projects/read-the-foo/
looks like its going now
after a full day of messing around
try triggering a rebuild for this: https://readthedocs.org/projects/adafruit-circuitpython-apds9960/
maybe they just had a minor outage
i had to setup a webhook on the github side, not use the "Integration..." one
maybe
simple as pushing a commit to trigger a rebuild?
that works or manually through their interface
oh. right. the "Update service" button under settings...hold.
github: " Okay, the hook was successfully updated."
why are you doing that?
won't that effectively make RTD do a build?
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
yeah, I'm fixing it
@timber mango checkout the hardware used in AdaBox 002:
https://learn.adafruit.com/adabox002
done
I believe that triggers a rebuild and it should work
looks like I can add something to readthedocs.yml to do it too
what about on RTD under Admin -> Intergrations
should anything be added there?
no, I add the integration on the github side
that part still doesn't work. just did a quick commit to repo. nothing on RTD.
which repo are you trying with?
that APDS9970 one:
https://github.com/caternuson/Adafruit_CircuitPython_APDS9960/commits/master
@idle owl so you're not working on driver, just want one for projects?
I can't see your settings on either side
adding the readthedocs integration on the github side should be enough
my github account is connected to my RTD
that seems to be the main difference
@tidal kiln Correct. I thought about trying to work on it since there wasn't one, but it's way outside my knowledge.
@idle owl ok. stay tuned then, i guess.
and I do see something listed under the RTD integrations tab
@tidal kiln Will do
right, I do have something listed there
maybe its added automatically because my accounts are linked
"Github incoming webhook" ?
yup
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...
that's a drop down, can't screen grab it easily, goes away when focus changes
where it says "No integrations are currently configured"
ah
I can't help you with that. why not link your accounts and re-add the integration from github?
guess i could, but nothing says thats necessary to get things to work
just makes it easier to config
docs aren't always complete or correct π
even Read The Docs docs?
https://github.com/rtfd/readthedocs.org#quickstart-for-github-hosted-projects
on the github side, you just have the entry under Integrations? nothing in Webhooks?
correct
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?
yeah, the path is included in the mpy when its built
pass in digitalio.DigitalInOut instead of pin
@slender iron thanks for the help. feel like this worked first time i went through your guide, but not since then.
no problem, maybe they changed things
yah. that's what it seems like.
The plot thickens!
:>
Plotter? Darn near killed'er!
so far so good, tomorrow will try integrating it into the mu editor!
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
I'm a newbie with this board. How do you hard reset it? I keep getting a file storage issue and I only have the main.py, lib folder (which is empty), and boot_out.txt. Thanks!
@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.
Have you all heard that the Python beater has been born? It is called Mongoose! Can CircuitMongoose be far behind? LOL π
@slender iron some plotzing occuring
not totally working yet but just needs a lil buffering
will keep hackin' till it mostly-works
Any idea when RFM69 might be supported on Feather M0 in MicroPython?
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 π
It should work.
I still keep getting the circuit python repl
That would be circuit python, yes. π
so it's definately circuit python still running
No question on that.
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.
Are you double-tapping the reset button to get to the bootloader?
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.
Now I feel silly
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.
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
UF2 is pretty great
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
where you pop your main.py
The CURRENT.UF2 is the entire file system
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.
Right
Probably half of it is for doing this dance
Fantastic π
I think I have a lot clearer picture now π
That's great!
I ordered these M0 boards a while ago - just got around to playing with them
Very excited
Congrats!
It's a good system and rather complete.
So, I could use platform io to build binaries, then convert to UF2 and bam!?
@signal root I don't know platform io, so I'm not sure.
Please do!
I'm sure there's others who would know, but sometimes it's rather quiet here over the weekend.
https://github.com/Microsoft/uf2
as well as
---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
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).
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
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).
I just built a blink hello world in platform.io and converted it to uf2 from the converter script from the microsoft repo
!
Plotter looks great @meager fog !
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?
@raven canopy I don't belive either the M0 or M4 are capable of multithreading
ahh. well, that would be a good reason not to plan for it or attempt it. π
I'm sure there are ways to do software multithreading but.... Honestly, it'd probably slow the device to a crawl
@raven canopy micropython does have some threading support but its untested in circuitpython. its not a high priority for us due to its complexity
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??
@slender iron cool. Thanks for the info.
@torn grail either should work. Just make sure the library matches the core implementation you are using. IE only circuitpython libraries work with circuitpython
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'
@stuck elbow may be able to help with micropython
otherwise try circuitpython
there is example code for it here: https://github.com/adafruit/Adafruit_CircuitPython_HT16K33/blob/master/examples/matrix.py
actually thats a matrix example, 7 segment is here: https://github.com/adafruit/Adafruit_CircuitPython_HT16K33/blob/master/examples/segments.py
Yeah -- thats matix, not 7segment
oh, there's segments
I'll do some more reading. Thanks @slender iron
π
@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?
@stuck elbow , so its bug that seven segment isn't there? I thought it was just me.
@torn grail it's a bug
@torn grail working on it now
@torn grail do you want to test?
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
@torn grail try this: https://github.com/deshipu/micropython-adafruit-ht16k33
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...)
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
it shows three of them [112, 113, 114] becuase I have them at 0x70, 0x71, 0x72
but not on 0x74?
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
I always find broken stuff. Thats my job!! But usually its in Java. So, I'm branching out.
Ouch, java
but at least we have it now tested by a professional tester π
let me know if you find any other problems
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.
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
If there is anything I can do to help, let me know
I guess I just need to start building something that uses it
and then I will need it
got the NRF21L01+ one working, though
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?
yes
The first works, but the second two are giberish on the display
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?
>>> display.fill(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Seg7x4' object has no attribute 'fill'
Phil would be said if there was no fill. LOL
hmm, I might need to add that fill, actually
there it goes
I'm using it in the 14seg display code
took out the fil command, now its hapier
@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.
@torn grail the fill() method is back https://github.com/deshipu/micropython-adafruit-ht16k33
@timber mango no worries
I guess I need to compile and flash the bootloader with the jlink
/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.
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?
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
I will try it on mine.
same with BOSSA-adafruit_17_10_19
@worn birch Revert your code to whatever previous state, or backup and remove the code you're working on. Then reset the board.
@stuck elbow is it possibly a circuit playground classic?
it has a flash chip on it
QuickQuestion: is there a millis() function on CircuitPython? Where? I'm using a CircuitPlayGroundExpress and can't find it.
@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.
and says 'express' on the back
@robust coral time.sleep(seconds)
@edgy hatch there is time.monotonic()
And that
@idle owl: not sleep, just need to know the time
@stuck elbow okay, its an express....I always check the simple things first
I'm time.sleeping(500) right now, cuz I forgot it was seconds, not microseconds! LOL
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.
that's what I need. Will try Thx
@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 I think it isn't going into bootloader mode.when you double click the reset button, all neopixels should turn green
@stuck elbow You ordered a Circuit Playground Express and it shipped without UF2 bootloader installed?
@idle owl I got it before it was on sale
Oooh.. ok. I was incredibly confused.
for testing
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 π
it has some differences, for example a transistor in place of the audio amplifier
I'm on the same page now.
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.
got the bootloader burned \o/
the jlink couldn't see it, but my trusty stlinkv2 worked
@stuck elbow Nice!
I think my mistake was the file format -- used BOSSAC to do an .UF2 which may be a forbidden combination.
OK, I tried the AudioIO example, and the transistor next to the speaker got hot
and I heard nothing and smelled smoke
@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...
Return the smoke to Adafruit (need an RSA number for that) and they will analyze it for future product development.
I guess that version has the audio circuit organized differently
@timber mango this is a product that was never sold anyways
@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"
@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.
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. π
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
The Makecode demo plays a very short sound during boot.
But it's an interesting sound. Like a voice in MIDI or something.
I'm generating those wav files with sfxr
@stuck elbow I have 4 in front of me that play wavs just fine. Could be software?
I suspect they don't begin/end on a neutral position, hence the clicks
you said "all" click and buzz tho.
I have a video
is it only at start and end of a sample?
Hmm, also if the speaker is initialising weird in the code, it'll click when it initialises and when it stops.
That's awesome!
there is a "pew" sound and an explosion sound, you can hear them behind all the clicks and buzzing
@stuck elbow That looks great! About the sound though hmm....
ruminants
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)
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)
here the amplifier is always on
You know it's not key-clicks from actuating the 4-way controller?
Maybe bridge the momentary switch contacts with a capacitor.
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
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?
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.
How long of a media file can the CPX present? Three seconds of clean audio?
After a try except catches an OSError: no SD card the next attempt to create an Adafruit_sdcard.SDCARD that doesn't get caught as an OSError: no SD card results in a CircuitPython core crash and subsequent boot into safe mode.
@stuck elbow Sweet ... so small ... looks cool ... can't imagine any teachers are going to be fans though.... but fun none the less!
@worn birch Thanks. I have a more teacher-friendly device, with an 8x8 LED display instead of the LCD.
@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?
CPX can play wavs for longer than that. The limiting issue is the file size, in my experience anyway.
@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).
that's weird, because the non-express versions of CircuitPython have the filesystem in flash
in the on-chip flash, I mean
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.
and I don't think they need a special bootloader?
well, how do you write to a filesystem if you can't address it?
to the internal on-chip flash?
It's a peripheral.
The internal flash is in the memory map. It's not a peripheral (per se).
@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.
Okay. I don't understand enough of it to have a lucid comment. I thought this was kind of cast in stone.
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?
Arduino.
I found a library for 328 flash writing. Will ook for one for SAMD flash writing
@timber mango iare you wa1tnr? or are you referring to wa1tnr's code as an exmaple?
I am himself. I have your cmaglie bookmarked since Feb 2017. I wonder why I moved past without looking at it!
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.
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.
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.
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.
@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
I really need to dig out my modules and test this properly
I will do that tomorrow, it's past midnight here
thanks, man. nite nite
just to make sure, display.text('1111') works?
what do you mean by "nope" exactly? what is shown?
when you use .text and not .number too?
I can test with you tomorrow if you want. I'm in California. Pacific time.
I'm 7segment, so no alpha. just numbers
I'm in CET, 9h difference
sure, but .text will still work with numbers
that's what .number uses internally
I'll try out some more things to see what I can "break"
thanks
@stuck elbow it's because of rounding errors with the 30bit floats. "{:f}".format(1111)gives '1110.999941' on a m0 ...
ouch
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
I'll try the .text and see how that goes
that looks like a bug; {:f} should do better than that
cpython has some smart rounding on display
yeah but 1111 should fit in 22 bits of mantissa
I think it always picks the shorter representation when there is ambiguity
>>> "{:f}".format(1111)
'1110.999941'
>>> 1111.0
1111.0
something is wrong with the arithmetic in format()
@torn grail you really have a talent!
Yes, ```
str(1111*1.0)
'1111.0'
So there is indeed something wrong in format...
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.
0.1 is a great choice π
ugh
having infinite representation in binary an all
i'll see if someone filed an issue on this in MicroPython.
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
Try the flash eraser. https://learn.adafruit.com/adafruit-circuit-playground-express/troubleshooting#for-the-circuit-playground-express-feather-m0-express-and-metro-m0-express
@idle owl thanks
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.
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)
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.
Everything looks good now.
Ok good
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.
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.
It wanted me to make a decision to replace every file.
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)
That wasn't flying too well. I must've done something wrong.
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?
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']
``
So that proves the bundle loaded?
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
great. yeah now we're talking.
Then do a dir(adafruit_dotstar)
thanks.
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.
``>>> 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.
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.
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.
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.
high-contrast different. or almost-the-same different.
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.
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.
Nice
Adafruit has rolled out CircuitPython so fast that it kind of moots what MakeCode can do for the CPX.
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.
Well, one is visual and drag and drop, the other is typing and reading reference literature. π
Valid point. But for someone who has literally never programmed anything in her life, MakeCode has been a great resource to get started with.
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
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.
and you give x its actual value
@timber mango Exactly.
I need to go soak my head in brine. For a long time. Thank you for your help, @idle owl
@timber mango You're welcome! I hope you get some good rest
whoa metro m4 testers whoa. I am going going gone. Goodnight.
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.
sure, no rush π
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
Nice!
is there a time.millis() or similar library call? time.monotonic is not granular enough
I think there's only time.monotonic().
Has anyone ever used the hardware timers in MicroPython to trigger functions at a specific interval? Other that PMW...
Just checking out CircuitPython because I have never programmed in Python before.. . .
Excellent! Welcome!
Ooh. Do you have a particular board you're using?
Just got a free Trinket M0 w/ my Oct. Adafruit order.
Nice! Checkout the Trinket guide! It's full of examples. https://learn.adafruit.com/adafruit-trinket-m0-circuitpython-arduino/circuitpython
Already read ladyadas's https://learn.adafruit.com/adafruit-trinket-m0-circuitpython-arduino/circuitpython-pwm?view=all
Well done there then! That's the best place to get started. If you've already finished that, then you'll want to start looking at other projects using CircuitPython. https://learn.adafruit.com/category/circuitpython
Not all of them will work with Trinket, but you might find some good information in other projects as well.
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 ?
it mounts as a usb drive with a file system
A 32-bit micro the size of my thumb - HA!!!!
you dont need anything else other than a text editor π
@wraith phoenix https://playground.arduino.cc/Linux/Debian
for arduinoo
@torn grail @stuck elbow re floating point formatting: https://github.com/micropython/micropython/issues/1450#issuecomment-348847212
thank you for the URL, kattni. Will look at it tomorrow.
@wraith phoenix We're here for questions as well! You're welcome!
Thanks for the URL, cascade. Could be my secret to success π
@wraith phoenix Also, check out the Welcome to the Community guide. Depending on your experience level, there are other resources that might be of use to you. https://learn.adafruit.com/welcome-to-the-community/welcome-to-the-community?view=all
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.
No worries!
Actually, it's half the size of my thumb π
@wraith phoenix π im excited to build one from scratch when i get the pcb's from osh park
@wraith phoenix just for practice and experience, i want to design and build my own board eventually :3
@cascaede Great! I am new to OSHW. But am a longtime linux user.
@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.
...That question probably would have gone better in #learn-adafruit-authors but too late now. Got CP on my mind.
@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. π
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
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!
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.
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.
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
Go ahead
@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
@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"
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
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
@slender iron ah, so something like dacData[0] = (x & FF00) >> 8