Sunday, July 16, 2023

Blink an LED or do other tasks asynchronously without using delay() on an Arduino

/* Blink Four LEDs Without Delay
  Adapted from Blink Without Delay
  by Steven J Greenfield, aka Polymorph
  Use however you like

I wrote this years ago. I'm not the only one, I'm not claiming that...

Note that I do the math and saving of the current time in such a way as to not cause cumulative timing errors, and to be immune to the rollover of millis(). For faster timed events, you can use micros() in place of millis(). You can even mix them, as long as each variable sticks with one or the other.

*/

// constants won't change. Used here to 

// set pin numbers:

const int ledPin0 =  2;      // the number of the LED0 pin

const int ledPin1 =  3;      // the number of the LED1 pin

const int ledPin2 =  4;      // the number of the LED2 pin

const int ledPin3 =  5;      // the number of the LED3 pin


// Variables will change:

int ledState0 = LOW;             // ledState used to set the LED0

int ledState1 = LOW;             // ledState used to set the LED1

int ledState2 = LOW;             // ledState used to set the LED2

int ledState3 = LOW;             // ledState used to set the LED3


// the follow variables are unsigned long because the time stored in millis() and micros()

// are unsigned long.

unsigned long previousMillis0 = 0;        // will store last time LED0 was updated

unsigned long previousMillis1 = 0;        // will store last time LED1 was updated

unsigned long previousMillis2 = 0;        // will store last time LED2 was updated

unsigned long previousMillis3 = 0;        // will store last time LED3 was updated


// the follow variables are unsigned long because the time stored in millis() and micros()

// are unsigned long.

unsigned long interval0 = 1000;           // interval at which to blink LED0 (milliseconds)

unsigned long interval1 = 457;           // interval at which to blink LED1 (milliseconds)

unsigned long interval2 = 1020;           // interval at which to blink LED2 (milliseconds)

unsigned long interval3 = 742;           // interval at which to blink LED3 (milliseconds)


void setup() {

  // set the digital pin as output:

  pinMode(ledPin0, OUTPUT);    

  pinMode(ledPin1, OUTPUT); 

  pinMode(ledPin2, OUTPUT); 

  pinMode(ledPin3, OUTPUT);   

}


void loop()

{

  // here is where you'd put code that needs to be running all the time.


  // check to see if it's time to blink the LED; that is, if the 

  // difference between the current time and last time you blinked 

  // the LED is bigger than the interval at which you want to 

  // blink the LED.


  // save the current time so it doesn't change during an operation

  unsigned long currentMillis = millis();


  // LED0 

  if(currentMillis - previousMillis0 >= interval0) {

    // save the last time you blinked the LED0 

    previousMillis0 += interval0;   // prevents time creep


    // if the LED is off turn it on and vice-versa:

    if (ledState0 == LOW)

      ledState0 = HIGH;

    else

      ledState0 = LOW;

  }


  //LED1

  if(currentMillis - previousMillis1 >= interval1) {

    // save the last time you blinked the LED0 

    previousMillis1 += interval1;   


    // if the LED is off turn it on and vice-versa:

    if (ledState1 == LOW)

      ledState1 = HIGH;

    else

      ledState1 = LOW;

  }


  //LED2

  if(currentMillis - previousMillis2 >= interval2) {

    // save the last time you blinked the LED0 

    previousMillis2 += interval2;   


    // if the LED is off turn it on and vice-versa:

    if (ledState2 == LOW)

      ledState2 = HIGH;

    else

      ledState2 = LOW;

  }


  //LED3

  if(currentMillis - previousMillis3 >= interval3) {

    // save the last time you blinked the LED0 

    previousMillis3 += interval3;   


    // if the LED is off turn it on and vice-versa:

    if (ledState3 == LOW)

      ledState3 = HIGH;

    else

      ledState3 = LOW;


    // set the LEDs with the ledStates of the variable:

    digitalWrite(ledPin0, ledState0);

    digitalWrite(ledPin1, ledState1);

    digitalWrite(ledPin2, ledState2);

    digitalWrite(ledPin3, ledState3);


  }

}


Sunday, May 7, 2023

How To Draw Schematic Diagrams

By Paul Horowitz and Winfield Hill
Appendix E from The Art of Electronics 2nd Edition
Cambridge University Press 1980, 1989.

A well-drawn schematic makes it easy to understand how a circuit works and aids in troubleshooting; a poor schematic only creates confusion. By keeping a few rules and suggestions in mind, you can draw a good schematic in no more time than it takes to draw a poor one. In this appendix we dispense advice of three varieties: general principles, rules, and hints. We have also drawn some real knee-slappers to illustrate habits to avoid.

General Principles

Schematics should be unambiguous. Therefore, pin numbers, parts values, polarities, etc., should be clearly labeled to avoid confusion.

A good schematic makes circuit functions clear. Therefore, keep functional areas distinct; don't be afraid to leave blank areas on the page, and don't try to fill the page. There are conventional ways to draw functional subunits; for instance, don't draw a differential amplifier as in Figure E1, because the function won't be easily recognized. Likewise, flip-flops are usually drawn with clock and inputs on the left, set and clear on top and bottom, and outputs on the right.


Figure E1: Placement of power rails and conventions

for device alignment (examples of what not to do)

Rules

  • Wires connecting are indicated by a heavy black dot; wires crossing, but not connecting, have no dot (don't use a little half-circular ``jog''; it went out in the 1950s).
  • Four wires must not connect at a point; i.e., wires must not cross and connect.
  • Always use the same symbol for the same device; e.g., don't draw flip-flops in two different ways (exception: assertion-level logic symbols show each gate in two possible ways).
  • Wires and components are aligned horizontally or vertically, unless there's a good reason to do otherwise.
  • Label pin numbers on the outside of a symbol, signal names on the inside.
  • All parts should have values or types indicated; it's best to give all parts a label, too, e.g., R7 or IC3.

Hints

  • Identify parts immediately adjacent to the symbol, forming a distinct group giving symbol, label, and type or value.
  • In general, signals go from left to right; don't be dogmatic about this, though, if clarity is sacrificed.
  • Put positive supply voltages at the top of the page, negative at the bottom. Thus, npn transistors will usually have their emitter at the bottom, whereas pnp's will have their emitter topmost.
  • Don't attempt to bring all wires around to the supply rails, or to a common ground wire. Instead, use the ground symbol(s) and labels like +Vcc to indicate those voltages where needed.
  • It is helpful to label signals and functional blocks and show waveforms; in logic diagrams it is especially important to label signal lines, e.g., RESET' or CLK.
  • It is helpful to bring leads away from components a short distance before making connections or jogs. For example, draw transistors as in Figure E2.


Figure E2: Component leads

  • Leave some space around circuit symbols; e.g., don't draw components or wires too close to an op-amp symbol. This keeps the drawing uncluttered and leaves room for labels, pin numbers, etc.
  • Label all boxes that aren't obvious: comparator versus op-amp, shift register versus counter, etc. Don't be afraid to invent a new symbol.
  • Use small rectangles, ovals, or circles to indicate card-edge connections, connector pins, etc. Be consistent.
  • The signal path through switches should be clear. Don't force the reader to follow wires all over the page to find out how a signal is switched.
  • Power-supply connections are normally assumed for op-amps and logic devices. However, show any unusual connections (e.g., an op-amp run from a single supply, where V- = ground) and the disposition of unused inputs.
  • It is very helpful to include a small table of IC numbers, types, and power-supply connections (pin numbers for Vcc and ground, for instance).
  • Include a title area near the bottom of the page, with name of circuit, name of instrument, by whom drawn, by whom designed or checked, date, and assembly number. Also include a revision area, with columns for revision number, date, and subject.
  • We recommend drawing schematics freehand on coarse graph paper (nonreproducing blue, 4 to 8 lines per inch) or on plain paper on top of graph paper. This is fast, and it gives very pleasing results. Use dark pencil or ink; avoid ball-point pen.

As an illustration, we've drawn a humble example (Figure E3) showing ``awful'' and ``good'' schematics of the same circuit; the former violates nearly every rule and is almost impossible to understand. See how many bad habits you can find illustrated. We've seen all of them in professionally drawn schematics! (Drawing the ``bad'' schematic was an occasion of great hilarity; we laughed ourselves silly.)

Figure E3 (A): An awful schematic


Figure E3 (B): A good schematic


Reprinted here as it seems it has disappeared from the original website and is only otherwise on a malware site. Cleansed of malware by putting it through text only transformation.

More resources:
https://electronics.stackexchange.com/questions/28251/rules-and-guidelines-for-drawing-good-schematics

https://www.k-state.edu/edl/docs/pubs/technical-resources/Technote8.pdf

https://www.allaboutcircuits.com/textbook/reference/chpt-9/wires-and-connections/

Monday, April 24, 2023

Malaprops I've heard and read

What they said versus what they meant or should have meant to say:
For all intensive purposes - For all intents and purposes
Purport - comport
Problematic, problematical - a problem
Dynamical - dynamic
Illicit a response - elicit a response
Glance over - gloss over
Come to the foray - come to the fore
In toto - in total
In total - in toto
Inaction - in action
Prescribe to - subscribe to
Prescribe - proscribe
Insure - ensure
Contemporaneously - contemporary
Casual - causal
Good - well
Electronical - electronic
Deep seeded - deep seated
First seed - first seat
Pass time - pastime
Past time - pastime 
Colloquially - collectively
I'm not going to enact that labor - I'm not going to explain myself
Daring-do - derring-do
Hare's breath - hair's breadth
Interior motive - ulterior motive
Analogical - analog
Mute point - moot point
Digitalize - digitize
Palatable - palpable
Regulated - relegated
Hone in on - Home in on
Not put a fine tooth point on it - not to put too fine a point on it
Wizened - wise
Apart - a part
Clean-cut - clear-cut
Regimen - regime
Into - in to
Reticent - reluctant
Passably - passively
Went down - gone down
Fermented - fomented as in to foment rebellion or foment change
Wroten - written or wrote
Broughten - brought
Boughten - bought
Self-depreciating - self-deprecating
Pacific - specific
Conversating - conversing
Could of, should of, would of - could have, should have, would have
Orientated - oriented
Defying new standards - defining new standards
Lose - loose
Periodically - intermittently
Martyr - pariah
Eminent - imminent
Citate - cite
Complimentary - complementary
Compliment - complement
Degradate - degrade
Misunderestimated - underestimated
Characteristical - characteristic
Epitaph - epithet
Revelation - revolution
Effect - affect
Affect - effect
Is - are
Are - is
Went - gone
Dwell - delve
Cosigned to the past - consigned to the past
Dissidence - dissonance
Configurating - configuring
Saw - seen
Seen - saw
Aloud - allowed
Advice - advise
"cutting off her nose,in spite of herself" - Cut off her nose to spite her face

Of course, the perennial "your, you're" and "their, they're, there"

Friday, November 11, 2022

A well-researched, plainly-written book about the long history of electricity leading to the modern electrified world

 OK, let's see how well posting a link from GoodReads works in my blog:



The Lightning Tamers: True Stories of the Dreamers and Schemers Who Harnessed Electricity and Transformed Our WorldThe Lightning Tamers: True Stories of the Dreamers and Schemers Who Harnessed Electricity and Transformed Our World by Kathy Joseph
My rating: 5 of 5 stars

Well researched and plainly written. I learned quite a lot about the history of the discovery of electricity and the invention and development of the science and devices that lead to our modern electrified world.

Highly recommend.

View all my reviews

Friday, July 29, 2022

Why I write in all caps

 I just write everything in capital letters.

My parents are adamant that my 2nd grade teacher ruined my handwriting, and that it was very good before that.

You know how some kids say their grades are bad because their teacher hates them, Well, my =parents= said that about my 2nd grade teacher. She found some fault in everything I did. I got so I didn’t know what was right in my handwriting, and got locked in analysis paralysis while writing, especially longhand but printing, too.

She had the typical alphabet examples on the wall around the room. But they showed more than one way to do some letters in longhand, like G, S, P, and R. Then she’d mark me down if I chose the wrong example, but she would not unequivocally state which was the one I was supposed to follow. Nor would she cover the ones she did not want us to follow.

I also get impatient when writing. My thoughts flow much faster than I can write.

^My handwriting in the mid-80s. Originally drawn only for my own use.

^ Same schematic, redrawn this year. Note that 12 years ago, I had manual drafting as part of an EET AT degree that included a lot of practice lettering all in caps.

^ My handwriting earlier this year. As you can see, I now write almost exclusively in all caps.

^ A couple of years ago, prior to chemo. If I don’t like how I’ve written a letter, I will erase and rewrite it. I have a particular problem with K and R.

^ Even when I put a fair amount of effort into it, my writing isn’t that great. Everything just wants to get out so fast.

Steve’s Hackaday.io Projects

Wednesday, July 27, 2022

Digital Photography and Composites on an Amiga computer

 Back in the mid '90s, I built a digital photography/compositing business around an Amiga 3000. There was even an interview with me published in Amiga Format magazine.

The Amiga 3000 was a great machine. I was using a desktop A3000 with a MicroniK case that gave me a lot more Zorro III and bridgeboard slots. At first, I used a video camera to capture still images, but that just wasn't high enough resolution for print. So as what I was doing expanded, I eventually ended up with a Phase 5 68060 accelerator and Cybervision 64 graphics card and a Polaroid digital camera that captured 1600x1200 tethered via the SCSI bus. Massive 128MB of RAM, a 1G Seagate SCSI, a 4G Fast SCSI 2 Micropolis AV drive on the Amiga SCSI bus, and a 4G Wide SCSI 3 Micropolis AV drive on the accelerator SCSI bus.

No Amiga drivers for the digital camera I was using (Polaroid PDC-2000), so I ran Shapeshifter and captured with Apple's Mac OS, System 6 (or 7, don't recall now). Since no Mac ever had a 680x0 greater than a 68040 and the PowerPC Macs at that time emulated the 68k chip, my Amiga was faster as a Mac than any Mac. How much faster? When I had the camera demo'd to me in Seattle on a PowerPC Mac, it took nearly 10 minutes to transfer an image from camera to computer. But my 68060 Amiga 3000 took about 15 seconds.

We went to sci fi conventions and composited people into custom backdrops in their costumes. I'd have an inkjet printing out a high res glossy, which took about 15 minutes then, while I had Real3D (a 3D modeling/rendering program) rendering several scenes or elements in the background, while working on a multiple layered graphic at 2400x3000 pixels in ImageFX, then I'd pop over to Shapeshifter to snap someone in their costume while my wife posed them. Printing and rendering continued uninterrupted, and everything ran smooth as silk.

The first Norwescon that we took this to, I had six different Microsoft programmers watch me and talk to me while I was working, and they'd suddenly say "Bill Gates ruined software!" after finding out that I was doing all of this on one computer running at 60MHz.

Between conventions, we'd work from home. I also repaired computers, especially Amigas, and other electronics. For a few years, we also had a science fiction collectibles store.

I had a Primera Pro dye sub printer that required an absolutely uninterrupted stream of data from the computer or the print would be ruined. If you were running Windows, it was best to make sure nothing was running but the print driver, and don't touch the mouse or keyboard. I talked to other people using this printer with Windows 95 on Pentium 100 and up who had prints ruined because they moved the mouse, and it might take 20 minutes to over an hour for the computer to process the file for printing.

It took my Amiga 3000 almost exactly 60 seconds between when I hit Print and the printer started. I tested it really hard one day - I hit Print, then quickly started Real3D and set three different high res 2400x3000 pixel images rendering, dialed into my ISP, started my web browser and opened a dozen tabs on different websites. The result? It took 2 minutes before it started printing, and the print itself was flawless. At no time did my typing or mouse pointer get jerky.

My old website is still up, although the digital photography business is gone. I never took orders online, so no shopping cart. Before you look at it, keep in mind that I never claimed to be an artist.

http://www.polyphoto.com

Hello, Hackaday viewers! If the above website doesn't link, please try again in a bit. Turns out there was a problem with the nameservers. I've fixed it, but it may take a few hours for the changes to propagate.

http://hackaday.com/2016/06/05/how-an-amiga-graphics-business-ran-in-the-1990s/

Update:

I’m inordinately excited – I was cleaning out my storage, and discovered that a friend of mine had given me an A3000, still in the original box! It needs a SCSI hard drive, and I think I have some RAM ZIP chips to max it out (it has 12M now, I think), and I am sure it could use a recapping… but… the battery DID NOT LEAK!

I have a 1G SCSI drive in a removable drive to install in it. I also found I have Kickstart 3.1 chips for it, and both Workbench 3.1 floppies and Workbench 3.9 on CD. I have a portable SCSI CDRom drive. I still have CD reader/burner software. Most of the other software is gone, however I kept a disk image of my original hard drive installation including Directory Opus and ImageFX 3.something.

I find I’m ridiculously excited about this.

What was owning a Commodore Amiga like?

 It was wonderful! The Amiga could multitask like no other consumer computer.

I had a digital photography business using an Amiga for photo compositing (like Photoshop), 3D rendering, special effects, and desktop publishing. My now rather old website is still online. Not up to today's standards, I know, but we did these compositions live while the customer waited, something you really could not do on a Windows computer in 1995:
Polymorph Digital Photography- Digital Portrait Photos and Composites

It had a 68060, which was a Motorola RISC processor, running at 50MHz with 128MB of RAM. We'd take it to science fiction conventions where we'd take pictures of people in their costumes and composite them into scenes and deliver the prints a bit later that day.

I ran a program called Directory Opus, or DOpus for short, as a Workbench replacement. It made the Amiga operating system, Workbench, even more of a joy to use.

I would typically have an image processing program called ImageFX running with between 6 and 20 layers, with the previous image printing on an inkjet (which at the time took 15 minutes to print an 8x10 photo), with a 3D modeling/rendering program called Real3D rendering things to composite into the image, and a Mac emulator running with the software for the tethered SCSI camera and the software to access Corel stock images CDs. All running at the same time.

The first convention we sold our services at was Norwescon, and 6 separate times over the weekend while chatting with different Microsoft programmers, they'd burst out with "Bill Gates ruined software" from watching all I was doing.

And while all this was going on, the printer did not stutter. My mouse did not freeze or stutter. Drawing selections and such in ImageFX was smooth, even with all that stuff going on at the same time....

When we had the equipment back home (home office, then shared space inside a sci fi collectibles store), I'd also have my web browser running with a dozen or so tabs open at the same time, often while running the Mac emulator and printing to a dye sub printer while making coffee cup prints, and running ImageFX, Real3D, and a desktop publishing program whose name escapes me.

And the mouse was so smooth... no hesitations. Typing was smooth. I could have Real3D rendering several high resolution images (2400x3000 pixels) while printing, -and- start other programs with no perceptible effect.

Nothing like Windows. I also owned a Windows 3.1 computer, and then a Windows 95 system so that I could run Pagemaker (desktop publishing). Even when using a Pentium 333MHz, Windows 95 stunk. I could not render in 3D and do anything else. If it was printing to the inkjet or rendering in 3D, I could -not- start another program without the whole thing becoming nonresponsive for several minutes, during which printing and/or rendering would stop and both the mouse and keyboard would stop responding.

In Windows 95, even if I started Pagemaker before beginning to print or render, typing or using the mouse would become a nightmare.

It wasn't until PCs started to get well over 1GHz clock speed before the interface started to feel as smooth as that 50MHz Amiga.

PCs are now really stinking fast, with more RAM than all the hard drives I had connected to my Amiga 3000. If only Commodore hadn't been gutted by Medhi Ali and Irving Gould, who knows what we'd have now?

Funny thing- it is not the hardware. I still have an old Pentium 200MMX with Windows 95 on it. It even has the same graphic chip on the video card that my Amiga had. But it stinks on ice. Slow, jerky... but I also have an Amiga emulator, Amiga Forever, running on it. Windows 95 stinks at multitasking, but it sees Amiga Forever as a single task. So within the Amiga emulator, it runs like the fastest Amiga ever!

I upgrade my Amiga Forever version every few years, and I still have the hard drive image from my now-defunct Amiga 3000. Once in a while I start it up and play around in it, and remember...

Amiga Emulation, Games, History and Support Since 1997

We even had a 3 page article done about my business in Amiga Format in 1998: