User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Sun Jul 22, 2018 5:00 am

Mortimer wrote:
Sat Jul 21, 2018 4:52 pm
You could try this...
https://www.codecademy.com

Codecademy seems good if you wish to learn many programming languages in a short time and becomes a pro. But to become a codecademy pro, you need to pay up.

I like MIT OpenCourseWare the most because everything is free. I could online 'sit in' their lecture halls, 'join in' the classes and tutorials. I am glad to have learned Python and many other engineering things 'when I was in MIT'.

I also like edX where also everything is free. Again 'when I was in Harvard', I attended many lectures outside engineering. The rock star I admire most is Michael Sandel. I remember vividly I once sat in Harvard's huge lecture hall and very excitedly felt that I was a real, non fake Harvard man.

JusticeHarvard
http://justiceharvard.org/

MIT OpenCourseWare - Wikipedia
https://en.wikipedia.org/wiki/MIT_OpenCourseWare

MIT OpenCourseWare (MIT OCW) is an initiative of the Massachusetts Institute of Technology (MIT) to publish all of the educational materials from its undergraduate – and graduate-level courses online, freely and openly available to anyone, anywhere.

MIT OpenCourseWare is a large-scale, web-based publication of MIT course materials. The project was announced on April 4, 2001 and uses Creative Commons Attribution-Noncommercial-Share Alike license.

The program was originally funded by the William and Flora Hewlett Foundation, the Andrew W. Mellon Foundation, and MIT. Currently, MIT OpenCourseWare is supported by MIT, corporate underwriting, major gifts, and donations from site visitors.

The initiative has inspired more than 250 other institutions to make their course materials available as open educational resources through the Open Education Consortium.

As of May 2018, over 2,400 courses were available online. While a few of these were limited to chronological reading lists and discussion topics, a majority provided homework problems and exams (often with solutions) and lecture notes. Some courses also included interactive web demonstrations in Java, complete textbooks written by MIT professors, and streaming video lectures.

As of May 2018, 100 courses included complete video lectures. The videos were available in streaming mode, but could also be downloaded for viewing offline. All video and audio files were also available from YouTube, iTunes U and the Internet Archive.


edX - Wikipedia
https://en.wikipedia.org/wiki/EdX

edX is a massive open online course (MOOC) provider. It hosts online university-level courses in a wide range of disciplines to a worldwide student body, including some courses at no charge. It also conducts research into learning based on how people use its platform. EdX is a nonprofit organization and runs on the free Open edX open-source software platform.

The Massachusetts Institute of Technology and Harvard University created edX in May 2012. More than 70 schools, nonprofit organizations, and corporations offer or plan to offer courses on the edX website.[5] As of 29 December 2017, edX has around 14 million students taking more than 1,800 courses online.


Coursera - Wikipedia
https://en.wikipedia.org/wiki/Coursera

Coursera is an online learning platform founded by Stanford professors Andrew Ng and Daphne Koller that offers courses, specializations, and degrees.

Coursera works with universities and other organizations to offer online courses, specializations, and degrees in a variety of subjects, such as engineering, humanities, medicine, biology, social sciences, mathematics, business, computer science, digital marketing, data science, and others.

As of June 2018, Coursera had more than 33 million registered users and more than 2,400 courses.

Codecademy - Wikipedia
https://en.wikipedia.org/wiki/Codecademy

Codecademy is an online freemium interactive platform that offers free coding classes in 12 different programming languages including Python, Java, JavaScript (jQuery, AngularJS, React.js), Ruby, SQL, and Sass, as well as markup languages HTML and CSS. The site also offers a paid "pro" option that gives users access to a personalized learning plan, quizzes, realistic projects, and live help from advisors.

Udacity - Wikipedia
https://en.wikipedia.org/wiki/Udacity

Udacity is a for-profit educational organization founded by Sebastian Thrun, David Stavens, and Mike Sokolsky offering massive open online courses (MOOCs)

According to Thrun, the origin of the name Udacity comes from the company's desire to be "audacious for you, the student". While it originally focused on offering university-style courses, it now focuses more on vocational courses for professionals.
Last edited by tlfong01 on Mon Jul 23, 2018 5:28 am, edited 6 times in total.
I am an electronics and smart home hobbyist.

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Sun Jul 22, 2018 6:27 am

Mortimer wrote:
Mon Jul 09, 2018 5:43 am
Permanent Magnet Synchronous Motor ... I have a clock like that. ...

I felt jealous of someone's PMSM clock. So I made myself one.

Permanent Magnet Synchronous Motor Clock
https://youtu.be/Tpci92yh0i8
Attachments
YgYs7En[1].jpg
YgYs7En[1].jpg (37.92 KiB) Viewed 1710 times
I am an electronics and smart home hobbyist.

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Sun Jul 22, 2018 6:53 am

tlfong01 wrote:
Sun Jul 22, 2018 5:00 am
Mortimer wrote:
Sat Jul 21, 2018 4:52 pm
You could try this...
https://www.codecademy.com
Codecademy seems good if you wish to learn many programming languages in a short time and becomes a pro. But to become a pro, you need to pay up.

I think Codecademy is misleading people who want to become a pro in a short time. I agree with @BoyOh saying that it takes more than 50 years to become a pro.

LOOKING FOR SOME CRASH COURSE OR SOMETHING 2018-Jul-21 Sat
viewtopic.php?f=91&t=218622&p=1343657#p1343441

I'm a programmer with absolutely no experience in electronics and stuff. I've decided to make an outfit using ...
I wish to learn, but I'd like to take the quickest path that will take me to my goal instead of going through tons of tutorials.


RE: LOOKING FOR SOME CRASH COURSE OR SOMETHING - boyoh » 2018-Jul-22
viewtopic.php?f=91&t=218622&p=1343657#p1343657

Now you know why Programmers are Cheap, and Electronic Engineers are worth their Weight in Gold
I've been on that quick electronic's course for 50yrs and not finished it yet
BoyOh


RE: LOOKING FOR SOME CRASH COURSE OR SOMETHING - 2018-Jul-22
viewtopic.php?f=91&t=218622&p=1343657#p1343658

Some words of wisdom from somebody who's been at your predicament before

"Haste makes waste..."

"... what seems as an 'easy way' is usually the hardest, most frustrating than the normal way..."
Take time to study first before implementing your project that suits your requirements....
Last edited by tlfong01 on Mon Jul 23, 2018 1:35 am, edited 1 time in total.
I am an electronics and smart home hobbyist.

User avatar
DougieLawson
Posts: 36520
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Relay Module KY-019 5V

Sun Jul 22, 2018 7:34 am

tlfong01 wrote:
Sun Jul 22, 2018 6:53 am
tlfong01 wrote:
Sun Jul 22, 2018 5:00 am
Mortimer wrote:
Sat Jul 21, 2018 4:52 pm
You could try this...
https://www.codecademy.com
Codecademy seems good if you wish to learn many programming languages in a short time and becomes a pro. But to become a pro, you need to pay up.
I think Codecademy is misleading people who want to become a pro in a short time. I agree with @BoyOh saying that it takes more than 50 years to become a pro.
I've been programming things since 1980, one day I'll consider myself an expert at this stuff.

Take 10,000 hours at https://www.learnpython.org and as https://www.bbc.co.uk/news/magazine-26384712 tells you'll be an expert in python (which is a truly ugly language with a horrible syntactic anomaly and the lack of a CASE/SWITCH construct).
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Sun Jul 22, 2018 7:43 am

tlfong01 wrote:
Sat Jul 21, 2018 12:57 pm
DougieLawson wrote:
Sat Jul 21, 2018 9:40 am
Here's a collection of functions to make driving your MCP23017 easier.
I think I need to google and study for one or two hours to fully understand all the functions.
And before that I need to read again the very complicated datasheet of MCP23017. I think I already spent 10 hours or so but still forgot things now and then, and still found some bits confusing.

Anyway, just now I skimmed the datasheet once more, and to keep things staying in my little aging head a little bit longer, I drew and redrew, and redrew, the following block diagram.
Attachments
GNE5FAf[1].jpg
GNE5FAf[1].jpg (41.63 KiB) Viewed 1682 times
Last edited by tlfong01 on Sun Jul 22, 2018 2:35 pm, edited 1 time in total.
I am an electronics and smart home hobbyist.

User avatar
DougieLawson
Posts: 36520
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Relay Module KY-019 5V

Sun Jul 22, 2018 7:49 am

The MCP23017 in basic, simple GPIO mode is the simplest I2C device of them all. You do nothing more than poke bits into IODIRA/IODIRB and OLATA/OLAB registers.

Reading GPIO as inputs is marginally more complex depending whether you want the INTA or INTB pins to be triggered when a GPIO changes state. If you don't want that it's a simple poll the GPIOA/GPIOB register and do stuff with the results.

So that's four registers that need bytes written to them and two that you read.

Stop over thinking it. Sharpen your coding pencil and give it a go, you can't break the thing (unless you exceed 5V on a GPIO).
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Sun Jul 22, 2018 1:31 pm

DougieLawson wrote:
Sun Jul 22, 2018 7:49 am
The MCP23017 in basic, simple GPIO mode is the simplest I2C device of them all.
Stop over thinking it. Sharpen your coding pencil and give it a go, ..
Well, I must first go to the drawing board, sharpen my drawing pencil, and draw a schematic.

Haste makes waste.
Attachments
inxhkKh[1].jpg
inxhkKh[1].jpg (95.47 KiB) Viewed 1638 times
I am an electronics and smart home hobbyist.

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Sun Jul 22, 2018 1:57 pm

tlfong01 wrote:
Sun Jul 22, 2018 1:31 pm
Well, I must first go to the drawing board, sharpen my drawing pencil, and draw a schematic.
Haste makes waste.

Then go to the photographic studio to take a photo.

My grandmother always says:

Slow craft makes fine goods.
Attachments
IvBg2Rr[1].jpg
IvBg2Rr[1].jpg (188.77 KiB) Viewed 1632 times
I am an electronics and smart home hobbyist.

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Sun Jul 22, 2018 2:27 pm

DougieLawson wrote:
Sun Jul 22, 2018 7:49 am
Reading GPIO as inputs is marginally more complex depending whether you want the INTA or INTB pins to be triggered when a GPIO changes state. If you don't want that it's a simple poll the GPIOA/GPIOB register and do stuff with the results.

Ah, I want interrupt functions, and also a Minimal, Complete, and Verifiable example.

How do I ask a good question? - Stack Overflow
https://stackoverflow.com/help/how-to-ask


How to create a Minimal, Complete, and Verifiable example - Stack Overflow
https://stackoverflow.com/help/mcve
Attachments
tFibgMS[1].jpg
tFibgMS[1].jpg (163.63 KiB) Viewed 1620 times
I am an electronics and smart home hobbyist.

User avatar
davidcoton
Posts: 4243
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Relay Module KY-019 5V

Sun Jul 22, 2018 2:57 pm

tlfong01 wrote:
Sun Jul 22, 2018 2:27 pm
DougieLawson wrote:
Sun Jul 22, 2018 7:49 am
Reading GPIO as inputs is marginally more complex depending whether you want the INTA or INTB pins to be triggered when a GPIO changes state. If you don't want that it's a simple poll the GPIOA/GPIOB register and do stuff with the results.
Ah, I want interrupt functions, and also a Minimal, Complete, and Verifiable example.
I think you are jumping the gun a bit. Almost certainly you need to brush up your coding enough to write and use interrupt-driven code.
But the "Minimal, Complete, and Verifiable example" is what you post here when you have a problem. It is a bit of your code that is as small as possible, yet contains everything to demonstrate your problem, and has been tested (by you) to ensure it does just that. Other people can use that to understand your problem and suggest solutions.

Learning resources (including the Python language documentation) should contain examples with the same attributes :D .
Signature retired

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Mon Jul 23, 2018 4:29 am

tlfong01 wrote:
Fri Jul 13, 2018 3:17 am
... I bought my RpiZero W from Argon40 in 2018dec, for HK$117.75 (= USD15).
... Rpi's authorized distributor in China
https://703805.world.taobao.com/index. ... 689295IRpl
is now selling Rpi ZW for also around USD15 (RMB105).
https://item.taobao.com/item.htm?id=55 ... acQAvD_BwE
Anyway, next time perhaps I could get my second RpiZW from them, with cheaper delivery fee, ...

The time has come to get my second RpiZW. The reason is that I have just started testing with my one and only one RpiZW. I could not sleep well if there is a problem seemingly with the RpiZW board, but I have no second board to do swap troubleshooting. It is like that one doctor says that I seemingly have cancer, but there is no second doctor to ask for a second opinion, ...

SMbus Reading Notes

While waiting for the second RpiZW, I am googling and reading about I2C/SMBus MCP23017 projects to clarify my mind on SMBus/I2C and MCP23017. The following is an interesting project on SMBus. I am glad to know what other hobbyists and/or students are playing with Rpi and I2C.

Enabling Inter-Integrated Circuit (I2C) communication with RPi.GPIO - Nithya Subramanian (ns796) & Aparna Ramanathan (ar2225) Final project for ECE 5990 spring 2016 at Cornell University
https://courses.cit.cornell.edu/ece5990 ... index.html

Enabling Inter-Integrated Circuit (I2C) communication with RPi.GPIO @Cornell University
https://www.youtube.com/watch?time_cont ... GLARFN-Mr0
Attachments
oo7ZNzM[1].jpg
oo7ZNzM[1].jpg (43.46 KiB) Viewed 1563 times
Last edited by tlfong01 on Mon Jul 23, 2018 1:50 pm, edited 2 times in total.
I am an electronics and smart home hobbyist.

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Mon Jul 23, 2018 7:49 am

tlfong01 wrote:
Sat Jul 14, 2018 1:38 pm
Mortimer wrote:
Thu Jul 05, 2018 9:31 am
  • ... turn any switches to on position on the project, then stand back and plug into a switched socket and turn on.
  • Once turned on, if you intend measuring for Voltages .use one hand only, the other kept well away and behind your back

I am wiring the high class 220VAC LED lamp for my studio. Your advice of putting one hand behind my back is not practical. The mains terminal connector is floating in the air. How can I use one hand to hold the thing, and use the same hand to hold a screw driver?

BTW, my lamp does not flicker. Big Clive in a youtube tore down a similar lamp (I now know that he should be world famous for tearing down things) and explained the circuit inside out, even showed the datasheet of the power electronic IC and circuit, and pointed out which resistor to modify, to adjust the brightness of the lamp. As usual, I learnt many news things that I didn't know that I didn't know,including the following:

  • 1. What I thought was a transformer is actually an inductor.
  • 2. How to solder components on to a big piece of aluminium sheet.
  • 3. Using an coffee maker as a heater base.
  • 4. The power electronics IC used is WinSemi current regulator WS3441.

I later googled power electronics articles and was very surprised to read that power electronics IC can direct interface with AC200V. I always wrongly thought that 36VDC was the limit.


Big Clive - Inside a 12W LED module
https://www.youtube.com/watch?v=rhlM2sPU_Z0&t=227s

Big Clive - LED Lamps Search Results
https://www.youtube.com/user/bigclivedo ... y=LED+lamp

WS3441 Datasheet
http://www.winsemi.com/en/upload/201406 ... 5_1530.pdf

Product Features

* Inductor Current Critical Mode, No Need to Compensate the Inductance Variation
* 500V MOSFET integrated
* Source Driver Structure, Not Need the Auxiliary Winding for VCC
* ±3% LED Current Accuracy
* Up to 93% System Efficiency
* LED Open/Short Circuit Protection
* Current Sense Resistor Short Circuit Protection
* Over Temperature Protection
* Programmable LED open protection
* Temperature compensation technology

Product Overview

* The WS3441 is a high precision constant current controller,designed for non-isolated buck LED driver. It can operate under universal AC input or 12V~500V DC input.
* The WS3441 integrates 500V power MOSFET, so it can achieve excellent constant current performance with very few external components.
* The WS3441 uses high precision current sense circuit and patent method for constant current control, to achieve high precision output current and excellent line regulation. The WS3441 operates in inductor current critical mode. The LED current is constant over wide range of inductance variation and the LED output voltage, so the load regulation is excellent.
* The WS3441 uses patent source driver architecture. The operation current is 200uA only, so the auxiliary winding is not needed. It can simplify the system design and reduce the system cost.
* WS3441 applies intelligent temperature compensation technology , can easily solve the problem of lights flashing at high temperature.
* The WS3441 offers rich protection functions, including LED open/short circuit protection, current sense resistor short circuit protection and over temperature protection.
Attachments
UTSIfTN[1].jpg
UTSIfTN[1].jpg (53.22 KiB) Viewed 1549 times
Last edited by tlfong01 on Tue Jul 24, 2018 6:57 am, edited 1 time in total.
I am an electronics and smart home hobbyist.

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Mon Jul 23, 2018 2:10 pm

tlfong01 wrote:
Mon Jul 23, 2018 4:29 am
SMbus Reading Notes
While waiting for the second RpiZW, I am googling and reading about I2C/SMBus MCP23017 projects to clarify my mind on SMBus/I2C and MCP23017.

I found the following two references useful for me to comfortably use SMBus commands in my first Rpi Zero W + MCP23017 python program.

SMBus Quick Start Guide - NXP
https://www.nxp.com/docs/en/application-note/AN4471.pdf

SMBus Protocol Summary (and commands)
https://git.kernel.org/pub/scm/linux/ke ... s-protocol

Useful Commands

SMBus Receive Byte: i2c_smbus_read_byte()
This reads a single byte from a device, without specifying a device
register. Some devices are so simple that this interface is enough; for
others, it is a shorthand if you want to read the same register as in
the previous SMBus command.

SMBus Send Byte: i2c_smbus_write_byte()
This operation is the reverse of Receive Byte: it sends a single byte
to a device. See Receive Byte for more information.

SMBus Read Byte: i2c_smbus_read_byte_data()
This reads a single byte from a device, from a designated register.
The register is specified through the Comm byte.

SMBus Read Word: i2c_smbus_read_word_data()
This operation is very like Read Byte; again, data is read from a
device, from a designated register that is specified through the Comm
byte. But this time, the data is a complete word (16 bits).

SMBus Write Byte: i2c_smbus_write_byte_data()
This writes a single byte to a device, to a designated register. The
register is specified through the Comm byte. This is the opposite of
the Read Byte operation.

SMBus Write Word: i2c_smbus_write_word_data()
This is the opposite of the Read Word operation. 16 bits
of data is written to a device, to the designated register that is
specified through the Comm byte.

SMBus Block Read: i2c_smbus_read_block_data()
This command reads a block of up to 32 bytes from a device, from a
designated register that is specified through the Comm byte. The amount
of data is specified by the device in the Count byte.

SMBus Block Write: i2c_smbus_write_block_data()
The opposite of the Block Read command, this writes up to 32 bytes to
a device, to a designated register that is specified through the
Comm byte. The amount of data is specified in the Count byte.

Not Useful Commands

SMBus Quick Command
This sends a single bit to the device, at the place of the Rd/Wr bit.

SMBus Process Call:
This command selects a device register (through the Comm byte), sends
16 bits of data to it, and reads 16 bits of data in return.

SMBus Host Notify
This command is sent from a SMBus device acting as a master to the
SMBus host acting as a slave.
It is the same form as Write Word, with the command code replaced by the
alerting device's address.

I2C Block Read: i2c_smbus_read_i2c_block_data()
This command reads a block of bytes from a device, from a
designated register that is specified through the Comm byte.

I2C Block Write: i2c_smbus_write_i2c_block_data()
The opposite of the Block Read command, this writes bytes to
a device, to a designated register that is specified through the
Comm byte. Note that command lengths of 0, 2, or more bytes are
supported as they are indistinguishable from data.
I am an electronics and smart home hobbyist.

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Mon Jul 23, 2018 3:15 pm

davidcoton wrote:
Sun Jul 22, 2018 2:57 pm
tlfong01 wrote:
Sun Jul 22, 2018 2:27 pm
Ah, I want interrupt functions, and also a Minimal, Complete, and Verifiable example.
  • 1. I think you are jumping the gun a bit. Almost certainly you need to brush up your coding enough to write and use interrupt-driven code.
  • 2. But the "Minimal, Complete, and Verifiable Example" is what you post here when you have a problem. It is a bit of your code that is as small as possible, yet contains everything to demonstrate your problem, and has been tested (by you) to ensure it does just that. Other people can use that to understand your problem and suggest solutions.
  • 3. Learning resources (including the Python language documentation) should contain examples with the same attributes :D .

Thanks a lot for your advice.

  • 1. I agree it is a bit over ambitious to play with interrupt now. So I will forget interrupt now and see if my first test programs go smoothly or not.
  • 2. I know the Minimal, Complete, and Verifiable example (MCVE) is used when I have a problem. However, I am using a different approach, as summarized below.
  • (2a) Write a very very simple MCVE, call it MCVE V1 which is so simple that I am sure it works. Debug myself if necessary.
  • (2b) Then write MCVE V2 by adding more features to MVCE V1. Debug myself if necessary.
  • (2c) Then write MCVE V3, MCVE V4, and so on, until MCVE Vn, which I got stuck and cannot debug myself. Now I have a problem. MCVE Vn is the MCVE that I will ask in the forum for help.
  • 3. My MCVE V1 to Vn-1 are not used to ask for help. It might be useful for newbies to see how a big program can grow from very very small to bigger and bigger, and finally a workable big program. (sort of system development by continuous integration and testing). The newbies might be interested to see how I write a big program step by step, as a learning resource.
Don't worry if you find me confusing. I might try to explain by my coming example programs.
I am an electronics and smart home hobbyist.

User avatar
davidcoton
Posts: 4243
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Relay Module KY-019 5V

Mon Jul 23, 2018 4:59 pm

tlfong01 wrote:
Mon Jul 23, 2018 3:15 pm
(2c) Then write MCVE V3, MCVE V4, and so on, until MCVE Vn, which I got stuck and cannot debug myself. Now I have a problem. MCVE Vn is the MCVE that I will ask in the forum for help.
I agree with the incremental approach to writing code. However, that means that the code is not "minimal". When you have a problem, the first thing to do is to remove any unnecessary (but known to work) code, leaving just enough to demonstrate the problem. Then your correspondents here don't have to examine all the working stuff to find the source of the problem. That is an MVCE. At that stage you may see the problem for yourself without needing to post!

There is a case for posting (blog-style) how your code develops, as you have done with the hardware. But don't confuse that with a request for help on a specific question. And try not to post the same code many times, it takes up space (both server space and page space) for no good purpose. Just post the day's new stuff, unless previous code has had a significant revision. Then re-post the whole thing at the end. (This is my preference, others, including the Mods, may have different ideas.)

Going back to learning about writing interrupt-driven code, don't try to handle input a different way then change to interrupt-driven. The code has a significantly different shape, so the input parts should be written that way from the start. The output handlers and the decision code in the middle don't affect that too much, but you need at least some input and some output to test anything. Depending on what I'm writing, I break my code down into units ("top down"), then write each bit bottom-up. I prioritise the "high-risk" parts (usually the bits that are new, require significant learning for me, or have memory or timing constraints that look tricky). In my current project (a long stalled heating controller), I wrote the user interface first, because Python and Tkinter were new to me and I could then track how much more code was needed to implement all the functions. Also, user interaction is key to the success of the project.
tlfong01 wrote:
Mon Jul 23, 2018 3:15 pm
Don't worry if you find me confusing. I might try to explain by my coming example programs.
I don't worry, except when you plan something unsafe or unwise. You minimise that risk by posting your plans, that is a good system. Seeing your plans and your thinking about how to develop your project is very interesting -- please don't stop!
Signature retired

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Tue Jul 24, 2018 5:44 am

tlfong01 wrote:
Mon Jul 23, 2018 7:49 am
WS3441 Datasheet
http://www.winsemi.com/en/upload/201406 ... 5_1530.pdf
Product Overview
* The WS3441 is a high precision constant current controller,designed for non-isolated buck LED driver. It can operate under universal AC input or 12V~500V DC input.
* The WS3441 integrates 500V power MOSFET, so it can achieve excellent constant current performance with very few external components.
* The WS3441 uses high precision current sense circuit and patent method for constant current control, to achieve high precision output current and excellent line regulation. The WS3441 operates in inductor current critical mode. The LED current is constant over wide range of inductance variation and the LED output voltage, so the load regulation is excellent.
* The WS3441 offers rich protection functions, including LED open/short circuit protection, current sense resistor short circuit protection and over temperature protection.[/i][/color]

My second Rpi Zero W arrives Hongkong this morning. So I can start dual RpiZW pair programming/development as early as this evening. But I need to first hurry up finishing with the LED lamp fixture.

My high class, ¥9.50, digital, constant current, multi (24) smoothly diffusive light sources, 'absolutely' no flicker, 6500K, 12W, LED light source module (no longer called "lamp", which sounds low tech and cheap) is now mounted on a bracket, with two degrees of freedom, on the 'ceiling' of my deluxe multfunction workbench. This AC220V light source module is to be controlled by the KY109 relay box, along with the Permanent Magnet Synchronous Motor Clock.

Now I am coming back to tidy up the buggy basic MCP23017 test functions and try to build my first Minimal, Complete, Verifiable, NoProblem Example (NCVNE) program.
Attachments
aRBkPgX[1].jpg
aRBkPgX[1].jpg (146.25 KiB) Viewed 1479 times
Last edited by tlfong01 on Tue Jul 24, 2018 9:24 am, edited 2 times in total.
I am an electronics and smart home hobbyist.

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Tue Jul 24, 2018 8:06 am

tlfong01 wrote:
Sun Jul 22, 2018 1:31 pm
Well, I must first go to the drawing board, sharpen my drawing pencil, and draw a schematic.

I found that I forgot the interrupt pins of MCP23017. So I redrew the schematic, at the same time expanding it to include the photocoupler EL817C and NPN BJT Darlington array ULN2803, with flyback diodes. For now the ULN2803 outputs only drive LEDs for testing. If everything goes smoothly, then I will replace the LEDs by relay switches.
Attachments
ifj7XVI[1].jpg
ifj7XVI[1].jpg (83.65 KiB) Viewed 1462 times
I am an electronics and smart home hobbyist.

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Tue Jul 24, 2018 8:28 am

tlfong01 wrote:
Tue Jul 24, 2018 5:44 am
Now I am coming back to tidy up the buggy basic MCP23017 test functions and try to build my first Minimal, Complete, Verifiable, NoProblem Example (NCVNE) program.
This morning I have finished NCVNE V1.3. But my programming was distracted by too many Google alerts, or other way round. So 

/Win10 language translation error, to continue later, ...
Attachments
HghRFvy[1].jpg
HghRFvy[1].jpg (116.31 KiB) Viewed 1455 times
I am an electronics and smart home hobbyist.

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Tue Jul 24, 2018 8:49 am

tlfong01 wrote:
Tue Jul 24, 2018 8:28 am
tlfong01 wrote:
Tue Jul 24, 2018 5:44 am
Now I am coming back to tidy up the buggy basic MCP23017 test functions and try to build my first Minimal, Complete, Verifiable, NoProblem Example (NCVNE) program.
This morning I have finished NCVNE V1.3. But my programming was distracted by too many Google alert reading, or other way round. So I remember very little what I have written, ...

Last post has corrupted Chinese characters. I don't know how to get rid of them. So I repost here, and will delete the old post later. My apologies for any language translation confusion.

/ to continue, ...
I am an electronics and smart home hobbyist.

User avatar
davidcoton
Posts: 4243
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Relay Module KY-019 5V

Tue Jul 24, 2018 8:58 am

I can see one Chinese character in the Config banner/comment in the code list. No others.
Signature retired

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Tue Jul 24, 2018 9:03 am

tlfong01 wrote:
Tue Jul 24, 2018 8:28 am
tlfong01 wrote:
Tue Jul 24, 2018 5:44 am
Now I am coming back to tidy up the buggy basic MCP23017 test functions and try to build my first Minimal, Complete, Verifiable, NoProblem Example (NCVNE) program.
This morning I have finished NCVNE V1.3. But my programming was distracted by too many Google alerts, or other way round. ...

In the last corrupted post, the image of Section 1 of 3 of the program is good. Now I am skipping Section 2, the boring functions, and jump directly to Section 3, the main test functions and the results.
Attachments
ptRY873[1].jpg
ptRY873[1].jpg (131.31 KiB) Viewed 1436 times
I am an electronics and smart home hobbyist.

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Tue Jul 24, 2018 12:34 pm

davidcoton wrote:
Tue Jul 24, 2018 8:58 am
I can see one Chinese character in the Config banner/comment in the code list. No others.

Thank you for your report.

You might also see at the end of the problematic post two or three lines of characters with different type face (not sans serif Arial) and double character spacing. I guess those are wrongly translated two byte long representation of Unicode of Chinese characters.

I think the problem is on my side, because I switch Windows 10 languages too frequent. I sometimes open over 10 Chrome windows at the same time, reading 4 newspapers in Simplified Chinese, 5 newspapers in Traditional Chinese, 1 BBC English 'newspaper', 1 Scottish English newspaper, and 2 American English fake newspapers.

I have already known for a long time that Win10 cannot catch up with my crazily fast language switching, so from time to time I need to pause a bit, otherwise Win10 cannot cope and locks up in one language and I need to reboot.

Anyway, I now attach Part 2 of my MCVNE V1.3. I originally wrote the python program in Rpi IDLE, and edit it in Win10 EditPlus which gives me line numbering but often with one bonus Chinese character before a python function definition.

This Part 2 has only 4 boring functions. I will do a selfi program walk through, perhaps tomorrow.
Attachments
UoMWOPh[1].jpg
UoMWOPh[1].jpg (125.92 KiB) Viewed 1415 times
I am an electronics and smart home hobbyist.

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Tue Jul 24, 2018 3:18 pm

tlfong01 wrote:
Tue Jul 24, 2018 12:34 pm
I will do a selfi program walk through, perhaps tomorrow.

Now I insert the complete program here. A big problem is that I am using very long names, making the statements too long to display in the code window without scrolling left and right.

So tomorrow I should build MCVNE V1.4 with shortened names.

Code: Select all

# KY019 MCP23017 Test Program V1.3 tlfong01 2018jul24hkt1247

# *** Short Description ***
# 1. Write one byte to a register and read it back.

# *** Long Description ***
# 1. Read and print the old byte already in the register IODIRA (Port A Direction Register with register address 0x00).
# 2. Write a new byte to the register.
# 3. Read back the new byte. 
# 4. Print the new byte.
# 5. Do it one more time.

# *** Import ***

import smbus

# *** Config ***

# Raspberry Pi                              = Raspberry Pi Zero W V1.1
# Raspbian                                  = Linux 9 (stretch 2018 April)

i2cPortSmBus1                               = smbus.SMBus(1)
mcp23017DevicAddressByte                    = 0x22
mcp23017PortAIoDirectionRegisterAddressByte = 0x00
testDataByte1                               = 0x55
testDataByte2                               = 0xaa

# *** Device Functions ***

def readDeviceRegisterOneByte            (i2cPort,  deviceAddressByte, deviceRegisterAddressByte):
    readByte = i2cPort.read_byte_data    (          deviceAddressByte, deviceRegisterAddressByte)
    return readByte

def writeDeviceRegisterOneByte           (i2cPort, deviceAddressByte, deviceRegisterAddressByte, writeByte):
    writeDeviceTwoBytes                  (i2cPort, deviceAddressByte, deviceRegisterAddressByte, writeByte)
    return

def writeDeviceTwoBytes                  (i2cPort, deviceAddressByte, dataByte1,                 dataByte2):
    i2cPort.write_byte_data              (         deviceAddressByte, dataByte1,                 dataByte2)
    return

def printDeviceRegisterOneByte           (i2cPort, deviceAddressByte, deviceRegisterAddressByte, printTitle):
    readByte = readDeviceRegisterOneByte (i2cPort, deviceAddressByte, deviceRegisterAddressByte)
    print                                (printTitle, hex(readByte))

# *** Test Functions ***

def testWriteReadPrintMcp23017PortAIoDirectionRegister(testDataByte):
    printDeviceRegisterOneByte(i2cPortSmBus1, mcp23017DevicAddressByte, mcp23017PortAIoDirectionRegisterAddressByte, 'Old Byte =')
    writeDeviceRegisterOneByte(i2cPortSmBus1, mcp23017DevicAddressByte, mcp23017PortAIoDirectionRegisterAddressByte, testDataByte)    
    printDeviceRegisterOneByte(i2cPortSmBus1, mcp23017DevicAddressByte, mcp23017PortAIoDirectionRegisterAddressByte, 'New Byte =')
    return

def test():
    testWriteReadPrintMcp23017PortAIoDirectionRegister(testDataByte1)
    testWriteReadPrintMcp23017PortAIoDirectionRegister(testDataByte2)
    return

# *** Main ***

test()

# *** Sample Output ***

# *** First Run ***
# Old Byte = 0xaa
# New Byte = 0x55

# *** Second Run ***
# Old Byte = 0x55
# New Byte = 0xaa

# *** End ***
I am an electronics and smart home hobbyist.

User avatar
davidcoton
Posts: 4243
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Relay Module KY-019 5V

Tue Jul 24, 2018 3:42 pm

The double spaced bit appeared in English:
/Win10 language translation error, to continue later, ...
You must have spent too much time on the fake English fake news sites :lol:
The Win10 tag was a good indication that it could be ignored :geek:
Signature retired

User avatar
tlfong01
Posts: 1312
Joined: Sat Jun 02, 2018 1:43 pm
Location: Hong Kong

Re: Relay Module KY-019 5V

Wed Jul 25, 2018 7:49 am

tlfong01 wrote:
Tue Jul 24, 2018 3:18 pm
tlfong01 wrote:
Tue Jul 24, 2018 12:34 pm
I will do a selfi program walk through, perhaps tomorrow.
So tomorrow I should build MCVNE V1.4 with shortened names.

This morning I shortened all the long names and the program now looks smart, as after a clean hair cut. I also walked through the program quickly and refactored things. Version 1.4 is listed below. I found more typo and format errors and would correct to Vision 1.5.

Code: Select all

# KY019 MCP23017 Test Program V1.4 tlfong01 2018jul25hkt1412

# *** Short Description ***
# 1. Write one byte to a register and read it back.

# *** Long Description ***
# 1. Read and print the old byte already in Port A Direction Register IODIRA.
# 2. Write a new byte to the register.
# 3. Read back the new byte. 
# 4. Print the new byte.
# 5. Do it one more time.

# *** Setup/Debug Notes ***
# 1. To change I2c speed to 100Khz
#    $ sudo nano /boot/config.txt
#    modify the dtparam=i2c_arm_on line as below 
#    dtparam=i2c_arm=on, i2c_arm_baudrate=100000
# 2. I2c speeds list
#    low speed      =  50kHz ( 50000) 
#    standard speed = 100KHz (100000)
#    maximum speed  = 400KHz (400000)
# 3. I2C speed can only be changed at raspbain boot time.  It cannot be changed using python.

# *** Import ***

import datetime
import smbus

# *** Config ***

# Raspberry Pi                              = Raspberry Pi Zero W V1.1
# Raspbian                                  = Linux 9 (stretch 2018 April)

programTitle                                = 'MCP23017 Example Test Program V1.4'
timeNowStr                                  = str(datetime.datetime.now())[0:16]
i2cCh1                                      = smbus.SMBus(1)
dvAddrByte                                  = 0x22
ioDirRegAddrByteA                           = 0x00
dataByte0x55                                = 0x55
dataByte0xaa                                = 0xaa

# *** Device Functions ***

def readDvRegOneByte                    (i2cPort, dvAddrByte, DvRegAddrByte):
    readByte = i2cPort.read_byte_data   (         dvAddrByte, DvRegAddrByte)
    return readByte

def writeDvRegOneByte                   (i2cPort, dvAddrByte, DvRegAddrByte, writeByte):
    writeDviTwoBytes                    (i2cPort, dvAddrByte, DvRegAddrByte, writeByte)
    return

def writeDviTwoBytes                    (i2cPort, dvAddrByte, dataByte1,     dataByte2):
    i2cPort.write_byte_data             (         dvAddrByte, dataByte1,     dataByte2)
    return

def printDvRegOneByte           (i2cPort, dvAddrByte, DvRegAddrByte, printTitle):
    readByte = readDvRegOneByte (i2cPort, dvAddrByte, DvRegAddrByte)
    print                       (printTitle, hex(readByte))

# *** Test Functions ***

def testWriteReadPrintIoDirRegA(testDataByte):
    printDvRegOneByte(i2cCh1, dvAddrByte, ioDirRegAddrByteA, 'Old Byte =')
    writeDvRegOneByte(i2cCh1, dvAddrByte, ioDirRegAddrByteA, testDataByte)    
    printDvRegOneByte(i2cCh1, dvAddrByte, ioDirRegAddrByteA, 'New Byte =')
    return

def test():
    print('*** TimeNow = ', timeNowStr, '***\n')
    print('***', programTitle, 'Begin ***\n')
    testWriteReadPrintIoDirRegA(dataByte0x55)
    testWriteReadPrintIoDirRegA(dataByte0xaa)
    print('\n')
    print('***', programTitle, 'End  ***')
    return

# *** Main ***

test()

# *** Sample Output ***

# *** TimeNow =  2018-07-25 15:25 ***

# *** MCP23017 Example Test Program V1.4 Begin ***

# Old Byte = 0xaa
# New Byte = 0x55
# Old Byte = 0x55
# New Byte = 0xaa


# *** MCP23017 Example Test Program V1.4 End  ***

# *** End ***
I am an electronics and smart home hobbyist.

Return to “Automation, sensing and robotics”