WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Micropython + GPIO  (Read 12991 times)

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Micropython + GPIO
« Reply #15 on: September 06, 2015, 10:34:37 PM »
Each line is 2 bytes long. If you are not closing the file output will be buffered and written at once causing unwanted wave form and timing on the GPIO pin.

Note: did not test with scope or analyzer, so it is just a theory :)
« Last Edit: September 06, 2015, 10:36:29 PM by bmarkus »
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Micropython + GPIO
« Reply #16 on: September 06, 2015, 10:38:32 PM »
Hi Bela,

Using up stock of my old Model B's.
Latest Luajit and Go not working any more, think they may already be compiled for ARM7, Pi2.


Interesting, will recheck. Thanks for reporting.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: Micropython + GPIO
« Reply #17 on: September 06, 2015, 10:45:38 PM »
Hi bmarkus
Why did you delete my post?

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Micropython + GPIO
« Reply #18 on: September 06, 2015, 10:46:40 PM »
Sorry, it was an accident :(
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: Micropython + GPIO
« Reply #19 on: September 06, 2015, 10:51:05 PM »
Hi bmarkus
No problem, I'll recreate it.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: Micropython + GPIO
« Reply #20 on: September 06, 2015, 11:01:57 PM »
Hi gavinmc42
Quote
Using your file method, python 2.7 flashes the led at 980Hz, Micropython does 2.8KHz, three times faster.
Maybe because of all the bloat stuff the normal python loads.
You set up the loop like this:
Code: [Select]
fp = open('/sys/class/gpio/gpio22/value', 'w')
while True:
    fp.write('1\n')
    fp.write('0\n')
Right? If you include the file open and close commands in the loop it will probably slow things down.

In response to bmarkus's comment:
Quote
Each line is 2 bytes long. If you are not closing the file output will be buffered and written at once causing unwanted wave form and timing on the GPIO pin.

Note: did not test with scope or analyzer, so it is just a theory
If that's the case, adding a flush command after each write would be appropriate.

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Micropython + GPIO
« Reply #21 on: September 06, 2015, 11:27:46 PM »
If that's the case, adding a flush command after each write would be appropriate.

The MicroPython os module do not have flush() method. You can make os.system('sync') but it is a slow operation. Need testing. Anyhow, MicroPython seems to be a valuable tool.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
Re: Micropython + GPIO
« Reply #22 on: September 07, 2015, 12:05:04 AM »
Smoking,
Micropython 58KHz, about the same for Lua on my multimeter.
Will have to stick CRO on pin to check jitter.

Sort of makes sense, GPIO pin is not really a file.
Probably will have more to do with locking?

Use script to write 16x2 LCD commands.
Some of my boxes really need an ip address display.
Could be a simple solution.
Write only to 5V LCD, can do that with 6 pins and 3.3v I/O.
Hmm PCB redesign.

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Micropython + GPIO
« Reply #23 on: September 07, 2015, 01:06:59 AM »
Hi Bela,

Using up stock of my old Model B's.
Latest Luajit and Go not working any more, think they may already be compiled for ARM7, Pi2.
Get an ARM6 expecting ARM7 warning.
Come to think of it maybe I only tested Go on the Pi 2.
Only reason for learning Go is the multicore capability, no need on old Pi's.

Will try the real python.tcz, stay tuned.

GO/LUAJIT issue confirmed, I will fix them.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
Re: Micropython + GPIO
« Reply #24 on: September 07, 2015, 01:49:20 AM »
Thanks Bela,

Interested in Lua because of Luajit.
Near C compiled speeds?


Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Micropython + GPIO
« Reply #25 on: September 07, 2015, 02:06:00 AM »
A year or so ago we made benchmarks. It was focusing on memory operations, allocations and not a full blown test. Winner was pure C. Next, very close GO and BACON BASIC compiler as a supprize. It was followed by LUAJIT a bit slower. Then far behind Ruby, than PERL and cPython. For sure it may very a bit depending on applications, but first three is expected are C/C++, GO and BACON. That time C# (Mono) was not tested.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Micropython + GPIO
« Reply #26 on: September 07, 2015, 05:07:27 AM »
Latest Luajit and Go not working any more, think they may already be compiled for ARM7, Pi2.

Tested luajit on piCore-7.0alpha3 running on old 'Rev B' RPi:

Code: [Select]
# uname -a
Linux box 4.1.6-piCore+ #1 PREEMPT Fri Aug 28 07:13:51 CEST 2015 armv6l GNU/Linux

# luajit -v
LuaJIT 2.0.3 -- Copyright (C) 2005-2014 Mike Pall. http://luajit.org/

# lua fact.lua
Enter a number:
6
720

# luajit fact.lua
Enter a number:
6
720

# lua hello.lua
Hello World

# luajit hello.lua
Hello World

It works fine as expected. Everything is freshly installed from the repo.

Can you show the case when it fails?


 
« Last Edit: September 07, 2015, 05:16:14 AM by bmarkus »
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
Re: Micropython + GPIO
« Reply #27 on: September 07, 2015, 07:52:32 PM »
I manually installed this version again.
http://distro.ibiblio.org/tinycorelinux/7.x/armv6/tcz/

I might have put the ARM7 version in by mistake.
Luajit is working now, version 2.0.3

file = io.open("/sys/class/gpio/gpio22/value", "w")
while true do
    file:write("1")
    file:flush()
    file:write("0")
    file:flush()
end

Took me a while to figure out that in Lua file write is buffered.
26KHz for Lua, about half speed of micropython because of the two extra file:flush() lines
92KHz same code -> Luajit


Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Micropython + GPIO
« Reply #28 on: September 08, 2015, 12:01:06 AM »
LuaJIT updated to 2.0.4
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
Re: Micropython + GPIO
« Reply #29 on: September 08, 2015, 12:40:45 AM »
Not yet pushed onto
http://distro.ibiblio.org/tinycorelinux/7.x/armv6/tcz/
?

Just noticed I've got old i2c-tools as well.

Micropython is now fast enough to drive a stepper motor, could not do it fast enough in shell.
Had just started designing a Cypress PSoC pcb to do the driving, controlled via i2c.
Now I can do it all on the Pi:)

Not sure if I want to do a three axis controller yet.