late chances and maixpy demo
This commit is contained in:
126
Maixpy_demo.ipynb
Normal file
126
Maixpy_demo.ipynb
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 1,
|
||||||
|
"metadata": {
|
||||||
|
"collapsed": true
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"\u001b[34mConnecting to --port=/dev/ttyUSB1 --baud=115200 \u001b[0m\n",
|
||||||
|
"\u001b[34mReady.\n",
|
||||||
|
"\u001b[0m"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"%serialconnect"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 2,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"Enter the ov2640_init\n",
|
||||||
|
"[MAIXPY]LCD:init\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"\n",
|
||||||
|
"import machine\n",
|
||||||
|
"c = machine.ov2640()\n",
|
||||||
|
"c.init()\n",
|
||||||
|
"l = machine.st7789()\n",
|
||||||
|
"l.init()\n",
|
||||||
|
"i = bytearray(320*240*2)\n",
|
||||||
|
"\n",
|
||||||
|
"c.get_image(i)\n",
|
||||||
|
"l.draw_picture_default(i)\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 11,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"."
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"for j in range(50):\n",
|
||||||
|
" c.get_image(i)\n",
|
||||||
|
" l.draw_picture_default(i)\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 10,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"[leftinbuffer] ['\\x04\\x04>']\n",
|
||||||
|
"GC: total: 1040384, used: 413728, free: 626656\n",
|
||||||
|
" No. of 1-blocks: 48, 2-blocks: 10, max blk sz: 12657, max free sz: 9014\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"Traceback (most recent call last):\n",
|
||||||
|
" File \"<stdin>\", line 4, in <module>\n",
|
||||||
|
"MemoryError: memory allocation failed, allocating 405300 bytes\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"for j in range(30):\n",
|
||||||
|
" c.get_image(i)\n",
|
||||||
|
" for x in range(100,120):\n",
|
||||||
|
" i[x*320*2 + 100:x*320*2 + 200] = b'0x99'*100\n",
|
||||||
|
" l.draw_picture_default(i)\n",
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "MicroPython - USB",
|
||||||
|
"language": "micropython",
|
||||||
|
"name": "micropython"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": "python",
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/python",
|
||||||
|
"name": "micropython"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 2
|
||||||
|
}
|
||||||
@@ -132,13 +132,14 @@ Other known projects that have implemented a Jupyter Micropython kernel are:
|
|||||||
* https://github.com/TDAbboud/mpkernel
|
* https://github.com/TDAbboud/mpkernel
|
||||||
* https://github.com/takluyver/ubit_kernel
|
* https://github.com/takluyver/ubit_kernel
|
||||||
* https://github.com/jneines/nodemcu_kernel
|
* https://github.com/jneines/nodemcu_kernel
|
||||||
|
* https://github.com/zsquareplusc/mpy-repl-tool
|
||||||
|
|
||||||
In my defence, this is not an effect of not-invented-here syndrome; I did not discover most of these
|
In my defence, this is not an effect of not-invented-here syndrome; I did not discover most of these
|
||||||
other projects until I had mostly written this one.
|
other projects until I had mostly written this one.
|
||||||
|
|
||||||
I do think that for robustness it is important to expose the full processes
|
I do think that for robustness it is important to expose the full processes
|
||||||
of making connections and But for my purposes, this is more robust and contains debugging (of the
|
of making connections. For my purposes this is more robust and contains debugging (of the
|
||||||
serial connections) capability.
|
serial connections) capability through its %lsmagic functions.
|
||||||
|
|
||||||
Other known projects to have made Jupyter-like or secondary interfaces to Micropython:
|
Other known projects to have made Jupyter-like or secondary interfaces to Micropython:
|
||||||
* https://github.com/nickzoic/mpy-webpad
|
* https://github.com/nickzoic/mpy-webpad
|
||||||
|
|||||||
@@ -423,9 +423,9 @@ class DeviceConnector:
|
|||||||
|
|
||||||
if bbinary:
|
if bbinary:
|
||||||
chunksize = 30
|
chunksize = 30
|
||||||
sswrite(b"import sys, os; O7=sys.stdout.write\r\n")
|
sswrite(b"import sys,os;O7=sys.stdout.write\r\n")
|
||||||
sswrite(b"import ubinascii; O8 = ubinascii.b2a_base64\r\n")
|
sswrite(b"import ubinascii;O8=ubinascii.b2a_base64\r\n")
|
||||||
sswrite("O=open({}, 'rb')\r\n".format(repr(sourcefilename)).encode())
|
sswrite("O=open({},'rb')\r\n".format(repr(sourcefilename)).encode())
|
||||||
sswrite(b"O9=bytearray(%d)\r\n" % chunksize)
|
sswrite(b"O9=bytearray(%d)\r\n" % chunksize)
|
||||||
sswrite("O4=os.stat({})[6]\r\n".format(repr(sourcefilename)).encode())
|
sswrite("O4=os.stat({})[6]\r\n".format(repr(sourcefilename)).encode())
|
||||||
sswrite(b"print(O4)\r\n")
|
sswrite(b"print(O4)\r\n")
|
||||||
@@ -438,8 +438,8 @@ class DeviceConnector:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
sswrite(b"O7(O8(O.read(O4%%%d)))\r\n" % chunksize) # get sub-block
|
sswrite(b"O7(O8(O.read(O4%%%d)))\r\n" % chunksize) # get sub-block
|
||||||
sswrite(b"while O.readinto(O9): O7(O8(O9))\r\n")
|
sswrite(b"while O.readinto(O9): O7(O8(O9))\r\n")
|
||||||
sswrite(b"O.close(); del O, O7, O8, O9, O4\r\n")
|
sswrite(b"O.close(); del O,O7,O8,O9,O4\r\n")
|
||||||
sswrite(b'\r\x04')
|
sswrite(b'\r\x04')
|
||||||
chunks = self.receivestream(bseekokay=True, bfetchfilecapture_nchunks=nbytes//chunksize+1)
|
chunks = self.receivestream(bseekokay=True, bfetchfilecapture_nchunks=nbytes//chunksize+1)
|
||||||
rres = [ ]
|
rres = [ ]
|
||||||
|
|||||||
@@ -267,7 +267,6 @@ class MicroPythonKernel(Kernel):
|
|||||||
self.sres("%lsmagic\n list magic commands\n\n")
|
self.sres("%lsmagic\n list magic commands\n\n")
|
||||||
self.sres(re.sub("usage: ", "", ap_mpycross.format_usage()))
|
self.sres(re.sub("usage: ", "", ap_mpycross.format_usage()))
|
||||||
self.sres(" cross-compile a .py file to a .mpy file\n\n")
|
self.sres(" cross-compile a .py file to a .mpy file\n\n")
|
||||||
self.sres("%readbytes\n does serial.read_all()\n\n")
|
|
||||||
self.sres(re.sub("usage: ", "", ap_readbytes.format_usage()))
|
self.sres(re.sub("usage: ", "", ap_readbytes.format_usage()))
|
||||||
self.sres(" does serial.read_all()\n\n")
|
self.sres(" does serial.read_all()\n\n")
|
||||||
self.sres("%rebootdevice\n reboots device\n\n")
|
self.sres("%rebootdevice\n reboots device\n\n")
|
||||||
@@ -374,7 +373,9 @@ class MicroPythonKernel(Kernel):
|
|||||||
if apargs.print:
|
if apargs.print:
|
||||||
self.sres(fetchedcontents.decode() if type(fetchedcontents)==bytes else fetchedcontents, clear_output=True)
|
self.sres(fetchedcontents.decode() if type(fetchedcontents)==bytes else fetchedcontents, clear_output=True)
|
||||||
if (apargs.destinationfilename or not apargs.print) and fetchedcontents:
|
if (apargs.destinationfilename or not apargs.print) and fetchedcontents:
|
||||||
fout = open(apargs.destinationfilename or apargs.sourcefilename, "wb" if apargs.binary else "w")
|
dstfile = apargs.destinationfilename or os.path.basename(apargs.sourcefilename)
|
||||||
|
self.sres("Saving file to {}".format(repr(dstfile)))
|
||||||
|
fout = open(dstfile, "wb" if apargs.binary else "w")
|
||||||
fout.write(fetchedcontents)
|
fout.write(fetchedcontents)
|
||||||
fout.close()
|
fout.close()
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -306,7 +306,7 @@
|
|||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"Connect through wifi to 192.168.0.142\r\n"
|
"Connect through wifi to 192.168.0.142\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -491,7 +491,7 @@
|
|||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"['__init__', 'remove_reader', 'wait', '__qualname__', 'add_writer', 'remove_writer', 'add_reader', '__module__', 'q', 'poller', 'objmap']\r\n"
|
"['__init__', 'remove_reader', 'wait', '__qualname__', 'add_writer', 'remove_writer', 'add_reader', '__module__', 'q', 'poller', 'objmap']\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -511,7 +511,7 @@
|
|||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"kernelspec": {
|
"kernelspec": {
|
||||||
"display_name": "MicroPython - /dev/ttyUSB0",
|
"display_name": "MicroPython - USB",
|
||||||
"language": "micropython",
|
"language": "micropython",
|
||||||
"name": "micropython"
|
"name": "micropython"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user