Category Archives: Hardware

Logitech K845ch mechanical keyboard

I just received a review unit of the Logitech K845ch mechanical keyboard. It has nice clicky keys, and lights under them. It can do five different light patterns at three different light levels. It’s interesting. One of the modes is a “react” mode so the key cap lights when you press it then quickly fades out.

I’ve missed these mechanical keyboards, so much. Thanks to Ed Snider’s work on the CoCoMech, I was made aware that they still exist. The unit I have used quiet switches, but I kinda want one with the loud clicking sound now… Fun!

Pi Problems.

I have six Raspberry Pis (three Pi Zero Ws, two Pi 3s, and one Pi 4). Tonight I tried to upgrade some of them.

  • My CoCo-Pi 3 unit booted and I was able to update it and install the latest CoCo-Pi emulator package.
  • My second Pi 3 booted to a kernel panic, and I am having to reinstall.
  • My first Pi Zero W got stuck on the Rainbow screen so I’ll have to reinstall it.
  • My second Pi Zero W has a different operating system running on it that I did not touch.
  • I also have a Pi 4 that is a retro game system, but I did not check it.

What makes these systems, when they just sit here idle (not powered on, haven’t been touched in months) not work? Anyone know?

I’ve had many Pis since the very first one came out, and I’ve had many issues with them over the years.

But I still buy more. Dunno why.

CoCoWiFi in the UK

Thanks to Rob Inman for sharing this link over on Discord. This was supposed to have been posted in July 2019, but I just found it in my drafts folder. I think I was going to write an article about it, but forgot.

Someone in the UK is selling an all-in-one RS-232 to WiFi adapter. They use Bo Zimmerman’s excellent Zimodem firmware, though the version they use is based on my fork of the project with the defaults set to standard RS-232 rather than Commodore’s inverted RS-232.

https://www.simulant.uk/shop/retro-vintage-computer-wifi-modem-rs232-serial-hayes-compatible

Arduino compatible bit Macros

Years ago, I cloned the Arduino IDE “bit” macros for use in a GCC program (for testing generic Arduino code on a different system). I dug them out recently for a work project, and decided to share them here. Maybe they will be useful to someone else. (And apologies for WordPress clobbering the ampersand and turning it to HTML. When I edit and view it, it looks good, then WordPress “helps” — even though I am using a Syntax Highlighter plugin specifically for code examples.)

#ifndef BITMACROS_H
#define BITMACROS_H
// Bit macros, based on Arduino standard.
// https://www.arduino.cc/reference/en/language/functions/bits-and-bytes/bit/
//
// x: the numeric variable to which to write.
// n: which bit of the number to write, starting at 0 for the least-significant (rightmost) bit.
// b: the value to write to the bit (0 or 1).
#define bit(n)              (1 << (n))
#define bitSet(x, n)        ((x) |= bit(n))
#define bitClear(x, n)      ((x) &= ~bit(n))
#define bitRead(x, n)       (((x) & bit(n)) !=0 )
#define bitWrite(x, n, b)   ((b) ? bitSet((x), (n)) : bitClear((x), (n)))
/* Verification tests:
bool showBits (uint32_t value, unsigned int bits)
{
    bool status;
    //printf ("showBits (%u, %u)\n", value, bits);
    if ((bits == 0) || (bits > sizeof(value)*8))
    {
        status = false;
    }
    else
    {
        // Must use signed to check against 0.
        for (int bit = (bits-1); bit >= 0; bit--)
        {
            printf ("%u", bitRead(value, bit));
        }
        printf ("\n");
    }
    return status;
}
int main()
{
    unsigned int value;
    // Test bit()
    for (unsigned int bit = 0; bit < 8; bit++)
    {
        printf ("bit(%u) = %u\n", bit, bit(bit));
    }
    printf ("\n");
    // Test bitSet()
    for (unsigned int bit = 0; bit < 8; bit++)
    {
        value = 0;
        printf ("bitSet(%u, %u) = ", value, bit);
        bitSet(value, bit);
        showBits (value, 8);
    }
    printf ("\n");
    // Test bitClear()
    for (unsigned int bit = 0; bit < 8; bit++)
    {
        value = 0xff;
        printf ("bitClear(%u, %u) = ", value, bit);
        bitClear (value, bit);
        showBits (value, 8);
    }
    printf ("\n");
    // Test bitRead()
    value = 0b10101111;
    showBits (value, 8);
    for (unsigned int bit = 0; bit < 8; bit++)
    {
        printf ("bitRead(%u, %u) = %u\n", value, bit, bitRead (value, bit));
    }
    printf ("\n");
    // Test bitWrite - 1
    value = 0x00;
    showBits (value, 8);
    for (unsigned int bit = 0; bit < 8; bit++)
    {
        printf ("bitWrite(%u, %u, 1) = ", value, bit);
        bitWrite (value, bit, 1);
        showBits (value, 8);
    }
    // Test bitWrite - 0
    showBits (value, 8);
    for (unsigned int bit = 0; bit < 8; bit++)
    {
        printf ("bitWrite(%u, %u, 0) = ", value, bit);
        bitWrite (value, bit, 0);
        showBits (value, 8);
    }
    printf ("\n");
    return EXIT_SUCCESS;
}
*/
#endif // BITMACROS_H
// End of BitMacros.h

Make C Pointers Great Again

Recently at my day job we stumbled upon a nasty compiler bug dealing with arrays of structures. On the PIC24 compiler we use, something as simple as this produced problematic code:

typedef struct
{
   char        name[100];
   int         value;
} ObjectStruct;
#define NUM_OBJECTS 2
// Globals
ObjectStruct objects[NUM_OBJECTS];
// Prototypes
void ShowObject (ObjectStruct object);
void main()
{
   int idx;
   
   for (idx = 0; idx < NUM_OBJECTS; idx++)
   {
      objects[idx].value = (100 + idx);
   }
   
   ShowObject (objects[0]);
   
   int n = 0;
   ShowObject (objects[n]);
}
void ShowObject (ObjectStruct object)
{
   printf ("object.value = %d\r\n", object.value);
}

The compiler appeared to generate reasonable code when accessing the structure element by constant “[0]”:

……………….. ShowObject (objects[0]);
*
0044C: MOV #800,W0
0044E: MOV #8D2,W1
00450: REPEAT #65
00452: MOV [W0++],[W1++]
00454: CALL 39A
………………..

…but when accessing it by variable “[n]” the code got ludicrous (prepare to scroll):

………………..
……………….. int n = 0;
*
00458: CLR 8CE
……………….. ShowObject (objects[n]);
0045A: MOV 8CE,W4
0045C: MOV #66,W3
0045E: MUL.SS W4,W3,W0
00460: MOV #800,W4
00462: ADD W0,W4,W0
00464: MOV #A,W4
00466: REPEAT #32
00468: MOV [W0++],[W4++]
0046A: MOV W5,8D2
0046C: MOV W6,8D4
0046E: MOV W7,8D6
00470: MOV W8,8D8
00472: MOV W9,8DA
00474: MOV W10,8DC
00476: MOV W11,8DE
00478: MOV W12,8E0
0047A: MOV W13,8E2
0047C: MOV W14,8E4
0047E: MOV W15,8E6
00480: MOV W0,8E8
00482: MOV W1,8EA
00484: MOV W2,8EC
00486: MOV W3,8EE
00488: MOV W4,8F0
0048A: MOV W5,8F2
0048C: MOV W6,8F4
0048E: MOV W7,8F6
00490: MOV W8,8F8
00492: MOV W9,8FA
00494: MOV W10,8FC
00496: MOV W11,8FE
00498: MOV W12,900
0049A: MOV W13,902
0049C: MOV W14,904
0049E: MOV W15,906
004A0: MOV W0,908
004A2: MOV W1,90A
004A4: MOV W2,90C
004A6: MOV W3,90E
004A8: MOV W4,910
004AA: MOV W5,912
004AC: MOV W6,914
004AE: MOV W7,916
004B0: MOV W8,918
004B2: MOV W9,91A
004B4: MOV W10,91C
004B6: MOV W11,91E
004B8: MOV W12,920
004BA: MOV W13,922
004BC: MOV W14,924
004BE: MOV W15,926
004C0: MOV W0,928
004C2: MOV W1,92A
004C4: MOV W2,92C
004C6: MOV W3,92E
004C8: MOV W4,930
004CA: MOV W5,932
004CC: MOV W6,934
004CE: MOV W7,936
004D0: MOV W6,8D4
004D2: MOV W7,8D6
004D4: MOV W8,8D8
004D6: MOV W9,8DA
004D8: MOV W10,8DC
004DA: MOV W11,8DE
004DC: MOV W12,8E0
004DE: MOV W13,8E2
004E0: MOV W14,8E4
004E2: MOV W15,8E6
004E4: MOV W0,8E8
004E6: MOV W1,8EA
004E8: MOV W2,8EC
004EA: MOV W3,8EE
004EC: MOV W4,8F0
004EE: MOV W5,8F2
004F0: MOV W6,8F4
004F2: MOV W7,8F6
004F4: MOV W8,8F8
004F6: MOV W9,8FA
004F8: MOV W10,8FC
004FA: MOV W11,8FE
004FC: MOV W12,900
004FE: MOV W13,902
00500: MOV W14,904
00502: MOV W15,906
00504: MOV W0,908
00506: MOV W1,90A
00508: MOV W2,90C
0050A: MOV W3,90E
0050C: MOV W4,910
0050E: MOV W5,912
00510: MOV W6,914
00512: MOV W7,916
00514: MOV W8,918
00516: MOV W9,91A
00518: MOV W10,91C
0051A: MOV W11,91E
0051C: MOV W12,920
0051E: MOV W13,922
00520: MOV W14,924
00522: MOV W15,926
00524: MOV W0,928
00526: MOV W1,92A
00528: MOV W2,92C
0052A: MOV W3,92E
0052C: MOV W4,930
0052E: MOV W5,932
00530: MOV W6,934
00532: MOV W7,936
00534: MOV W8,938
00536: MOV W7,8D6
00538: MOV W8,8D8
0053A: MOV W9,8DA
0053C: MOV W10,8DC
0053E: MOV W11,8DE
00540: MOV W12,8E0
00542: MOV W13,8E2
00544: MOV W14,8E4
00546: MOV W15,8E6
00548: MOV W0,8E8
0054A: MOV W1,8EA
0054C: MOV W2,8EC
0054E: MOV W3,8EE
00550: MOV W4,8F0
00552: MOV W5,8F2
00554: MOV W6,8F4
00556: MOV W7,8F6
00558: MOV W8,8F8
0055A: MOV W9,8FA
0055C: MOV W10,8FC
0055E: MOV W11,8FE
00560: MOV W12,900
00562: MOV W13,902
00564: MOV W14,904
00566: MOV W15,906
00568: MOV W0,908
0056A: MOV W1,90A
0056C: MOV W2,90C
0056E: MOV W3,90E
00570: MOV W4,910
00572: MOV W5,912
00574: MOV W6,914
00576: MOV W7,916
00578: MOV W8,918
0057A: MOV W9,91A
0057C: MOV W10,91C
0057E: MOV W11,91E
00580: MOV W12,920
00582: MOV W13,922
00584: MOV W14,924
00586: MOV W15,926
00588: MOV W0,928
0058A: MOV W1,92A
0058C: MOV W2,92C
0058E: MOV W3,92E
00590: MOV W4,930
00592: MOV W5,932
00594: MOV W6,934
00596: MOV W7,936
00598: MOV W8,938
0059A: MOV W9,93A
0059C: MOV W8,8D8
0059E: MOV W9,8DA
005A0: MOV W10,8DC
005A2: MOV W11,8DE
005A4: MOV W12,8E0
005A6: MOV W13,8E2
005A8: MOV W14,8E4
005AA: MOV W15,8E6
005AC: MOV W0,8E8
005AE: MOV W1,8EA
005B0: MOV W2,8EC
005B2: MOV W3,8EE
005B4: MOV W4,8F0
005B6: MOV W5,8F2
005B8: MOV W6,8F4
005BA: MOV W7,8F6
005BC: MOV W8,8F8
005BE: MOV W9,8FA
005C0: MOV W10,8FC
005C2: MOV W11,8FE
005C4: MOV W12,900
005C6: MOV W13,902
005C8: MOV W14,904
005CA: MOV W15,906
005CC: MOV W0,908
005CE: MOV W1,90A
005D0: MOV W2,90C
005D2: MOV W3,90E
005D4: MOV W4,910
005D6: MOV W5,912
005D8: MOV W6,914
005DA: MOV W7,916
005DC: MOV W8,918
005DE: MOV W9,91A
005E0: MOV W10,91C
005E2: MOV W11,91E
005E4: MOV W12,920
005E6: MOV W13,922
005E8: MOV W14,924
005EA: MOV W15,926
005EC: MOV W0,928
005EE: MOV W1,92A
005F0: MOV W2,92C
005F2: MOV W3,92E
005F4: MOV W4,930
005F6: MOV W5,932
005F8: MOV W6,934
005FA: MOV W7,936
005FC: MOV W8,938
005FE: MOV W9,93A
00600: MOV W10,93C
00602: MOV W9,8DA
00604: MOV W10,8DC
00606: MOV W11,8DE
00608: MOV W12,8E0
0060A: MOV W13,8E2
0060C: MOV W14,8E4
0060E: MOV W15,8E6
00610: MOV W0,8E8
00612: MOV W1,8EA
00614: MOV W2,8EC
00616: MOV W3,8EE
00618: MOV W4,8F0
0061A: MOV W5,8F2
0061C: MOV W6,8F4
0061E: MOV W7,8F6
00620: MOV W8,8F8
00622: MOV W9,8FA
00624: MOV W10,8FC
00626: MOV W11,8FE
00628: MOV W12,900
0062A: MOV W13,902
0062C: MOV W14,904
0062E: MOV W15,906
00630: MOV W0,908
00632: MOV W1,90A
00634: MOV W2,90C
00636: MOV W3,90E
00638: MOV W4,910
0063A: MOV W5,912
0063C: MOV W6,914
0063E: MOV W7,916
00640: MOV W8,918
00642: MOV W9,91A
00644: MOV W10,91C
00646: MOV W11,91E
00648: MOV W12,920
0064A: MOV W13,922
0064C: MOV W14,924
0064E: MOV W15,926
00650: MOV W0,928
00652: MOV W1,92A
00654: MOV W2,92C
00656: MOV W3,92E
00658: MOV W4,930
0065A: MOV W5,932
0065C: MOV W6,934
0065E: MOV W7,936
00660: MOV W8,938
00662: MOV W9,93A
00664: MOV W10,93C
00666: MOV W11,93E
00668: MOV W10,8DC
0066A: MOV W11,8DE
0066C: MOV W12,8E0
0066E: MOV W13,8E2
00670: MOV W14,8E4
00672: MOV W15,8E6
00674: MOV W0,8E8
00676: MOV W1,8EA
00678: MOV W2,8EC
0067A: MOV W3,8EE
0067C: MOV W4,8F0
0067E: MOV W5,8F2
00680: MOV W6,8F4
00682: MOV W7,8F6
00684: MOV W8,8F8
00686: MOV W9,8FA
00688: MOV W10,8FC
0068A: MOV W11,8FE
0068C: MOV W12,900
0068E: MOV W13,902
00690: MOV W14,904
00692: MOV W15,906
00694: MOV W0,908
00696: MOV W1,90A
00698: MOV W2,90C
0069A: MOV W3,90E
0069C: MOV W4,910
0069E: MOV W5,912
006A0: MOV W6,914
006A2: MOV W7,916
006A4: MOV W8,918
006A6: MOV W9,91A
006A8: MOV W10,91C
006AA: MOV W11,91E
006AC: MOV W12,920
006AE: MOV W13,922
006B0: MOV W14,924
006B2: MOV W15,926
006B4: MOV W0,928
006B6: MOV W1,92A
006B8: MOV W2,92C
006BA: MOV W3,92E
006BC: MOV W4,930
006BE: MOV W5,932
006C0: MOV W6,934
006C2: MOV W7,936
006C4: MOV W8,938
006C6: MOV W9,93A
006C8: MOV W10,93C
006CA: MOV W11,93E
006CC: MOV W12,940
006CE: MOV W11,8DE
006D0: MOV W12,8E0
006D2: MOV W13,8E2
006D4: MOV W14,8E4
006D6: MOV W15,8E6
006D8: MOV W0,8E8
006DA: MOV W1,8EA
006DC: MOV W2,8EC
006DE: MOV W3,8EE
006E0: MOV W4,8F0
006E2: MOV W5,8F2
006E4: MOV W6,8F4
006E6: MOV W7,8F6
006E8: MOV W8,8F8
006EA: MOV W9,8FA
006EC: MOV W10,8FC
006EE: MOV W11,8FE
006F0: MOV W12,900
006F2: MOV W13,902
006F4: MOV W14,904
006F6: MOV W15,906
006F8: MOV W0,908
006FA: MOV W1,90A
006FC: MOV W2,90C
006FE: MOV W3,90E
00700: MOV W4,910
00702: MOV W5,912
00704: MOV W6,914
00706: MOV W7,916
00708: MOV W8,918
0070A: MOV W9,91A
0070C: MOV W10,91C
0070E: MOV W11,91E
00710: MOV W12,920
00712: MOV W13,922
00714: MOV W14,924
00716: MOV W15,926
00718: MOV W0,928
0071A: MOV W1,92A
0071C: MOV W2,92C
0071E: MOV W3,92E
00720: MOV W4,930
00722: MOV W5,932
00724: MOV W6,934
00726: MOV W7,936
00728: MOV W8,938
0072A: MOV W9,93A
0072C: MOV W10,93C
0072E: MOV W11,93E
00730: MOV W12,940
00732: MOV W13,942
00734: MOV W12,8E0
00736: MOV W13,8E2
00738: MOV W14,8E4
0073A: MOV W15,8E6
0073C: MOV W0,8E8
0073E: MOV W1,8EA
00740: MOV W2,8EC
00742: MOV W3,8EE
00744: MOV W4,8F0
00746: MOV W5,8F2
00748: MOV W6,8F4
0074A: MOV W7,8F6
0074C: MOV W8,8F8
0074E: MOV W9,8FA
00750: MOV W10,8FC
00752: MOV W11,8FE
00754: MOV W12,900
00756: MOV W13,902
00758: MOV W14,904
0075A: MOV W15,906
0075C: MOV W0,908
0075E: MOV W1,90A
00760: MOV W2,90C
00762: MOV W3,90E
00764: MOV W4,910
00766: MOV W5,912
00768: MOV W6,914
0076A: MOV W7,916
0076C: MOV W8,918
0076E: MOV W9,91A
00770: MOV W10,91C
00772: MOV W11,91E
00774: MOV W12,920
00776: MOV W13,922
00778: MOV W14,924
0077A: MOV W15,926
0077C: MOV W0,928
0077E: MOV W1,92A
00780: MOV W2,92C
00782: MOV W3,92E
00784: MOV W4,930
00786: MOV W5,932
00788: MOV W6,934
0078A: MOV W7,936
0078C: MOV W8,938
0078E: MOV W9,93A
00790: MOV W10,93C
00792: MOV W11,93E
00794: MOV W12,940
00796: MOV W13,942
00798: MOV W14,944
0079A: MOV W13,8E2
0079C: MOV W14,8E4
0079E: MOV W15,8E6
007A0: MOV W0,8E8
007A2: MOV W1,8EA
007A4: MOV W2,8EC
007A6: MOV W3,8EE
007A8: MOV W4,8F0
007AA: MOV W5,8F2
007AC: MOV W6,8F4
007AE: MOV W7,8F6
007B0: MOV W8,8F8
007B2: MOV W9,8FA
007B4: MOV W10,8FC
007B6: MOV W11,8FE
007B8: MOV W12,900
007BA: MOV W13,902
007BC: MOV W14,904
007BE: MOV W15,906
007C0: MOV W0,908
007C2: MOV W1,90A
007C4: MOV W2,90C
007C6: MOV W3,90E
007C8: MOV W4,910
007CA: MOV W5,912
007CC: MOV W6,914
007CE: MOV W7,916
007D0: MOV W8,918
007D2: MOV W9,91A
007D4: MOV W10,91C
007D6: MOV W11,91E
007D8: MOV W12,920
007DA: MOV W13,922
007DC: MOV W14,924
007DE: MOV W15,926
007E0: MOV W0,928
007E2: MOV W1,92A
007E4: MOV W2,92C
007E6: MOV W3,92E
007E8: MOV W4,930
007EA: MOV W5,932
007EC: MOV W6,934
007EE: MOV W7,936
007F0: MOV W8,938
007F2: MOV W9,93A
007F4: MOV W10,93C
007F6: MOV W11,93E
007F8: MOV W12,940
007FA: MOV W13,942
007FC: MOV W14,944
007FE: MOV W15,946
00800: MOV W14,8E4
00802: MOV W15,8E6
00804: MOV W0,8E8
00806: MOV W1,8EA
00808: MOV W2,8EC
0080A: MOV W3,8EE
0080C: MOV W4,8F0
0080E: MOV W5,8F2
00810: MOV W6,8F4
00812: MOV W7,8F6
00814: MOV W8,8F8
00816: MOV W9,8FA
00818: MOV W10,8FC
0081A: MOV W11,8FE
0081C: MOV W12,900
0081E: MOV W13,902
00820: MOV W14,904
00822: MOV W15,906
00824: MOV W0,908
00826: MOV W1,90A
00828: MOV W2,90C
0082A: MOV W3,90E
0082C: MOV W4,910
0082E: MOV W5,912
00830: MOV W6,914
00832: MOV W7,916
00834: MOV W8,918
00836: MOV W9,91A
00838: MOV W10,91C
0083A: MOV W11,91E
0083C: MOV W12,920
0083E: MOV W13,922
00840: MOV W14,924
00842: MOV W15,926
00844: MOV W0,928
00846: MOV W1,92A
00848: MOV W2,92C
0084A: MOV W3,92E
0084C: MOV W4,930
0084E: MOV W5,932
00850: MOV W6,934
00852: MOV W7,936
00854: MOV W8,938
00856: MOV W9,93A
00858: MOV W10,93C
0085A: MOV W11,93E
0085C: MOV W12,940
0085E: MOV W13,942
00860: MOV W14,944
00862: MOV W15,946
00864: MOV W0,948
00866: MOV W15,8E6
00868: MOV W0,8E8
0086A: MOV W1,8EA
0086C: MOV W2,8EC
0086E: MOV W3,8EE
00870: MOV W4,8F0
00872: MOV W5,8F2
00874: MOV W6,8F4
00876: MOV W7,8F6
00878: MOV W8,8F8
0087A: MOV W9,8FA
0087C: MOV W10,8FC
0087E: MOV W11,8FE
00880: MOV W12,900
00882: MOV W13,902
00884: MOV W14,904
00886: MOV W15,906
00888: MOV W0,908
0088A: MOV W1,90A
0088C: MOV W2,90C
0088E: MOV W3,90E
00890: MOV W4,910
00892: MOV W5,912
00894: MOV W6,914
00896: MOV W7,916
00898: MOV W8,918
0089A: MOV W9,91A
0089C: MOV W10,91C
0089E: MOV W11,91E
008A0: MOV W12,920
008A2: MOV W13,922
008A4: MOV W14,924
008A6: MOV W15,926
008A8: MOV W0,928
008AA: MOV W1,92A
008AC: MOV W2,92C
008AE: MOV W3,92E
008B0: MOV W4,930
008B2: MOV W5,932
008B4: MOV W6,934
008B6: MOV W7,936
008B8: MOV W8,938
008BA: MOV W9,93A
008BC: MOV W10,93C
008BE: MOV W11,93E
008C0: MOV W12,940
008C2: MOV W13,942
008C4: MOV W14,944
008C6: MOV W15,946
008C8: MOV W0,948
008CA: MOV W1,94A
008CC: SUB #66,W0
008CE: MOV #8E8,W4
008D0: REPEAT #32
008D2: MOV [W0++],[W4++]
008D4: MOV #8EA,W4
008D6: REPEAT #32
008D8: MOV [W1++],[W4++]
008DA: MOV #8EC,W4
008DC: REPEAT #32
008DE: MOV [W2++],[W4++]
008E0: MOV #8EE,W4
008E2: REPEAT #32
008E4: MOV [W3++],[W4++]
008E6: MOV #8F0,W0
008E8: REPEAT #32
008EA: MOV [W4++],[W0++]
008EC: MOV #8F2,W0
008EE: REPEAT #32
008F0: MOV [W5++],[W0++]
008F2: MOV #8F4,W0
008F4: REPEAT #32
008F6: MOV [W6++],[W0++]
008F8: MOV #8F6,W0
008FA: REPEAT #32
008FC: MOV [W7++],[W0++]
008FE: MOV #8F8,W0
00900: REPEAT #32
00902: MOV [W8++],[W0++]
00904: MOV #8FA,W0
00906: REPEAT #32
00908: MOV [W9++],[W0++]
0090A: MOV #8FC,W0
0090C: REPEAT #32
0090E: MOV [W10++],[W0++]
00910: MOV #8FE,W0
00912: REPEAT #32
00914: MOV [W11++],[W0++]
00916: MOV #900,W0
00918: REPEAT #32
0091A: MOV [W12++],[W0++]
0091C: MOV #902,W0
0091E: REPEAT #32
00920: MOV [W13++],[W0++]
00922: SUB #CC,W14
00924: MOV #904,W0
00926: REPEAT #32
00928: MOV [W14++],[W0++]
0092A: SUB #CC,W15
0092C: MOV #906,W0
0092E: REPEAT #32
00930: MOV [W15++],[W0++]
00932: MOV #908,W0
00934: REPEAT #32
00936: MOV [W0++],[W0++]
00938: MOV #90A,W0
0093A: REPEAT #32
0093C: MOV [W1++],[W0++]
0093E: MOV #90C,W0
00940: REPEAT #32
00942: MOV [W2++],[W0++]
00944: MOV #90E,W0
00946: REPEAT #32
00948: MOV [W3++],[W0++]
0094A: MOV #910,W0
0094C: REPEAT #32
0094E: MOV [W4++],[W0++]
00950: MOV #912,W0
00952: REPEAT #32
00954: MOV [W5++],[W0++]
00956: MOV #914,W0
00958: REPEAT #32
0095A: MOV [W6++],[W0++]
0095C: MOV #916,W0
0095E: REPEAT #32
00960: MOV [W7++],[W0++]
00962: MOV #918,W0
00964: REPEAT #32
00966: MOV [W8++],[W0++]
00968: MOV #91A,W0
0096A: REPEAT #32
0096C: MOV [W9++],[W0++]
0096E: MOV #91C,W0
00970: REPEAT #32
00972: MOV [W10++],[W0++]
00974: MOV #91E,W0
00976: REPEAT #32
00978: MOV [W11++],[W0++]
0097A: MOV #920,W0
0097C: REPEAT #32
0097E: MOV [W12++],[W0++]
00980: MOV #922,W0
00982: REPEAT #32
00984: MOV [W13++],[W0++]
00986: MOV #924,W0
00988: REPEAT #32
0098A: MOV [W14++],[W0++]
0098C: MOV #926,W0
0098E: REPEAT #32
00990: MOV [W15++],[W0++]
00992: MOV #928,W0
00994: REPEAT #32
00996: MOV [W0++],[W0++]
00998: MOV #92A,W0
0099A: REPEAT #32
0099C: MOV [W1++],[W0++]
0099E: MOV #92C,W0
009A0: REPEAT #32
009A2: MOV [W2++],[W0++]
009A4: MOV #92E,W0
009A6: REPEAT #32
009A8: MOV [W3++],[W0++]
009AA: MOV #930,W0
009AC: REPEAT #32
009AE: MOV [W4++],[W0++]
009B0: MOV #932,W0
009B2: REPEAT #32
009B4: MOV [W5++],[W0++]
009B6: MOV #934,W0
009B8: REPEAT #32
009BA: MOV [W6++],[W0++]
009BC: MOV #936,W0
009BE: REPEAT #32
009C0: MOV [W7++],[W0++]
009C2: CALL 39A
………………..

UPDATE: A week after reporting this issue (and a related one), the tool provider sent us an updated .DLL file that seems to resolve it. Code generation is now much nicer!

Sadly, this isn’t the only such behavior we have found with this compiler in regards to structures.

But why are we trying to pass a structure in to a function? Wouldn’t it be much more efficient to pass it in by reference, as a pointer?

Yes.

Yes it would.

But pointer problems are one of the leading causes of system crashes. Checking that a pointer is not NULL only means it points somewhere, and does not ensure it points to the expected data.

If the code is mission critical, that pointer check needs to do much more. Perhaps have some ID values in the structure that have to be verified, and add a checksum/CRC to the data:

typedef struct
{
   uint16_2 id; // will be set to some value like 0x1234
   // your data
   // more of your data
   uint16_t checksum; // will be a checksum of the id and data bytes.
} SafeStruct;

Then, when that structure is initialized/created, the ID would get set, and any time values were updated, the checksum would be updated. Any function that gets passed a pointer to a SafeStruct would validate the id and then checksum before proceeding.

If the system happens to have memory protection, and the pointer is in some off-limits memory, that attempt to access the id could cause a BUS TRAP or memory access exception. So, other checks would be needed to see if the pointer is even in the expected range of application memory.

This can get tricky, but if we all coded like this, we’d have far less crashes. I believe, anyway.

But, C allows you to pass in a variable and a copy gets made for use in the the function. This generates extra code and is slower, but it’s safer since the function only works on a COPY of the data and not a pointer that could be wrong.

MyStruct foo;

function (foo); // function() gets a copy of foo to work with

To modify this and return a value, you could do something like this:

foo = function (foo);

But, that means you are no longer able to use the return value for error checking. To work around that, you might have an error field in the structure that is set before it returns.

Yep, extra steps. Larger code. Slower code. But if you are coding as if lives depend on it working, and don’t need every last clock cycle, it’s a good habit to get into.

Unless you are using this PIC24 compiler, in which case, it causes other problems.

Until next time…

CoCoWiFi fork of ZiModem updated to current 3.5 build.

Updates:

  • 2019-05-03: I’ve had a report of my build not allowing you to type. I have seen this before, and am investigating this. Anyone else having issues? Also, I missed something in my merge which may have affected over-the-air updates (AT&U). I am pushing out a new build. Also, added a screen shot showing 3.5. Also, note about no ESP32 build.
  • 2019-05-04: I started over with Bo’s unmodified source code, then did my changes to zimodem.ino and zcommand.ino. I am still seeing the issue where, via USB serial connection, I can’t type of my TTL-to-RS232 adapter is hooked up. Without it, it works fine. I need to do some testing via the CoCo with it’s bitbanger and RS-232 Pac ports to see what behavior I get. In the meantime, I appreciate your feedback.

Yesterday I updated my fork of Bo Zimmerman’s ZiModem. My custom fork is 100% his code, with only some configurations changed to make it default to standard RS-232 signals instead of inverted like the Commodore uses. (Basically, it’s what his “Guru modem” firmware defaults to, and the over-the-air update changed to point to builds on my service. Guru modem only builds for ESP32, so eventually I just need to figure out how to modify the project so it builds Guru modem for ESP8266, I think.)

NOTE: I only built for the NodeMCU-12E ESP8266 module and the generic ESP8266 (whatever that is) module. I did not have ESP32 libraries installed so there is no build for that currently.

If you want to pull the source code and build it directly through the Arduino IDE, you can find my fork here:

https://github.com/allenhuffman/Zimodem

The binaries I built are located here:

http://subethasoftware.com/files/zimodem/

I also wrote up some instructions for updating that firmware from a PC, Mac or Linux machine without having to build it with the Arduino IDE. (I had to use these steps myself, since I couldn’t remember how it worked.)

NOTE: If you have the ESP8266 wired up to a TTL-to-RS232 adapter, you may find that firmware updates will not work. On my device (using the full-signal TTL adapter and a NodeMCU ESP8266), I had to unplug the 3.3V power wire that goes from ESP8266 pin to the TTL-to-RS232 board. That was enough to make firmware updates work. I’m still not sure why having the TTL adapter hooked up affects loading firmware over USB, but apparently it does.

A final option is to use the ZiModem built-in over-the-air update capability, which we haven’t gotten to test yet since this is the first time I’ve updated firmware for the CoCoWiFi fork. That is done through the command:

AT&U

That should grab the latest build on my server. I believe it reads a .txt file from my server to get the version number and builds the filename out of that, then downloads that filename. You can also specify the version manually. Currently, there is a 3.4 build and a 3.5 build available on my site.

AT&U=3.5

Please let me know if this works for you. You should see the startup banner (1200 baud) show 3.5:

ZiModem (CoCoWiFi config) 3.5

Original instructions on this WiFi modem for $10 can be found here:

Good luck!

Wire up your own RS-232 WiFi modem for under $10 using ESP8266 and Zimodem firmware.

Updates:

  • 2018-03-02: Making link to separate article on installing firmware easier to notice.
  • 2018-07-28: Travis Poppe has a 3-D printed case for this you can download and print: https://www.thingiverse.com/thing:2923619
  • 2020-05-01: Reformatting for current WordPress. Renaming some images.

This is a fairly detailed guide to configuring a cheap ESP8266 WiFI module to act as a WiFi modem, then wiring it up to any computer with a traditional RS-232 port.

It can be as simple as hooking up four wires, or many more wires, or even making a breadboard prototype:

Hardware Needed

  1. ESP82660-12E NodeMCU 1.0 development module (or a NodeMCU ESP-32S module)
  2. microUSB cable and power source (either powered by a computer’s USB port, or a standalone USB power supply like a phone charger)
  3. RS-232 to TTL adapter that operates at 3.3V.
  4. Female-to-female jumper wires (or male-to-male jumper wires and a breadboard)
  5. RS-232 cable (and possibly an RS-232 gender changer or NULL modem adapter)

Software Needed

Currently, we have to download and build the special Zimodem firmware, but as soon as I figure out what it takes just to load a pre-built binary, this section will be removed.

  1. Serial Drivers for the development module you choose.
  2. Zimodem firmware for the ESP by Bo Zimmerman.
  3. ESP firmware flash tool (or Arduino IDE if you want to download and build the source code yourself).

HARDWARE

ESP Development Module

The ESP8266 is a tiny WiFi device that can also run custom code. The development module version has a built-in USB-Serial adapter that can be used for debugging and loading firmware, and also gives a convenient way to power the module.

  • I started out with a NodeMCU ESP8266-12E module from Amazon for $8.29, available with 2-day Prime shipping. I later ordered a batch of five for $25 from this e-Bay reseller (shipped from the US). You can also find them for under $4 each if shipped from China.
  • The ESP32 is also supported, like this ESP32-WROOM-32 NodeMCU 32-S module for $12.99 on Amazon. They can be also be found for under $6 shipped from China. The ESP32 adds support for Bluetooth, but the firmware we will be using currently does not make use of it. The only real reason to use it is that Zimodem for ESP32 will be built using standard RS-232 signals, while the Zimodem build for ESP8266 has inverted RS-232 signals for Commodore computers, and will require some additional setup to make work on non-Commodore machines.
  • Even an under-$2 ESP-01 will work if you are not needing full RS-232 signals like hardware flow control and carrier detect. However, you will need more hardware to program it and power it, so I just stick with one of the development boards that has USB built in. (It actually cost me more to order an ESP-1 plus the USB programming adapter than to buy one of the devkits with everything built in.)

microUSB Cable and power supply

You will need a standard USB to microUSB cable to hook the ESP to a computer so you can load the firmware. Most Android phones use this type of cable, as do things like the Raspberry Pi. If you don’t have one, you can probably buy one at the local gas station.

This cable will also provide power for the ESP module, so it will need to be hooked to a computer’s USB port, or into a USB power supply like a phone charger. Again, commonly available even at the local gas station.

RS-232 to TTL Adapter

The ones I found have a standard DB9 female connector and contain circuitry that will convert the 3.3V chip-level TTL signals used by the ESP chip to standard 12V RS-232 levels that a computer uses. These will often will come with a short 4-wire jumper cable that can be used to hook them up to the ESP module.

  • If all you want is just transmit and receive (referred to as a “3-wire” hookup), you can go with a simple one like this $7 one from Amazon (there are also ones under $6), or find them for less with slower shipping (under $1 shipped from China). These provide hookups for TX (transmit), RX (receive), VCC (power) and GND (ground). For simple uses, this may be all you need. MAKE SURE THE ADAPTER SUPPORTS 3.3V! Some only work with 5V and are not compatible with the ESP modules. WARNING: Some of the ones I tried that claimed they operated at 3.3V did not, so it may take some trial and error.
  • If you also need hardware flow control (referred to as a “5-wire” hookup), there are adapters that a add extra connections for CTS and RTS. They are usually cost just a dollar or so more. (Here is a $10 one from Amazon, but I’ve found them for under $4 on eBay.)
  • If you need full RS-232 signals, including carrier detect, I have found two sources of adapters that provide TX (transmit), RX (receive), DCD (data carrier detect), CTS (clear to send), RTS (request to send), DTR (data terminal ready), DSR (data set ready), and RI (ring indicator).
  • Pololu 23201a Serial Adapter – available asssembled for $11.50, or in a partial kit for $9.95. This adapter uses one row of 10 pins, and is breadboard friendly.  However, I have had been some issues with this part, so I cannot currently recommend it. If you try it and can get it to work, please let me know.
  • AIBANS.BREAKOUT Adapter – available through Amazon for $4.68+$3.03 shipping from California reseller MD Fly, or $3.25+$3.65 standard shipping through their e-Bay listing. (On eBay, you can get a shipping discount for ordering multiple units.) This one works great for me, but it uses a dual-row of pins so it is not breadboard friendly.

Jumper Wires (Female-to-Female)

Most of the RS-232 to TTL adapters I have seen come with a set of jumper wires with female ends. They slide over the pins on the board, and then slide over the pins of whatever you are connecting it to. They allow hooking up parts without needing soldering skills or even a breadboard. I find bundles of 40 of these for under $3.

This .92 cent adapter, shipped from China, came with jumper wires.

Optional: Breadboard and Male-to-Male Jumper Wires

Optionally, if you want something that is a bit more “stable” (without exposed pins and such), you can use a breadboard and male-to-male jumper wires, then plug everything up and jumper them together.

RS-232 Cable and Adapters

You will need a cable to go from your computer’s RS-232 port to the adapter. Your cable will depend on the type of RS-232 to TTL adapter you have. All the ones I have use DB-9 female connectors, but there are some that use a male connector.

For example, my Radio Shack Color Computer has a 4-pin DIN connector for the built-in Serial I/O port. Back then, cables where made that had a male 4-pin DIN connector on one end (to plug into the CoCo) and a male DB-25 connector on the other (to plug into a modem). If I could find my old cables, I could use them, but I would still need a DB-25 to DB-9 adapter to go between that cable and the smaller DB-9 connector of the RS-232 to TTL adapter.

Another common type of serial cable is a NULL modem cable, which was used to hook two computers together by serial ports. I have a NULL modem cable that has the male 4-PIN DIN connector on one end and a female DB-9 on the other. Since it is a NULL modem cable, it has the TX and RX lines swapped so it can plug directly to a “modern” PC’s serial port DB-9 male connector. To use this cable, I needed a male DB-9 to male DB-9 NULL modem adapter, which will swap the TX and RX again, making it a normal cable like the RS-232 to TTL adapter requires, and change the gender so it will plug into the TTL adapter.

I also have the Deluxe RS-232 Program Pak, which provides a full RS-232 port with a female DB-25 connector. To use that, I ordered a standard male DB-25 to male DB-9 cable from Amazon. This will plug directly from my RS-232 Pak to the RS-232 to TTL adapter.

Basically, you will need whatever serial cable your system requires and a way to convert it to plug into a DB-9 connector.

SOFTWARE

The ESP modules have their own software installed, and it includes a command mode where you can use “AT” commands (similar to the old Hayes Smartmodem standard) to do various WiFi things. But, this is not setup to emulate an old modem connection. Instead, we will use Bo Zimmerman’s excellent replacement firmware called Zimodem. He provides the source code, but you will have to download and build it, then load it into your module.

I am now maintaining a special version of Zimodem that has things set up for normal RS-232 use. (By default, the original Zimodem works in a Commodore mode for 8266, and normal for ESP32. My version works in normal mode for both.)

Serial Drivers

Most of the low-cost ESP parts use serial hardware that is not recognized by a Mac or PC (not sure about Linux). If you plug up your ESP part to your computer and it is not recognized as a serial port (Like COM5: on windows, or /dev/cu.SLAB_USBtoUART on Mac), you will need drivers.

Most sellers will provide links to where to find drivers. For the Amazon parts I purchased, they used the CP2012 chipset, and I had to download and install the drivers for it. Once installed, you can plug the ESP module up and it should show up as a new serial port device.

Firmware Flash Utilities

Because of the various methods available to install ESP firmware, I have split them out into a separate article.

Please read this article for details on how to load the firmware onto the module without needing to install the Arduino IDE, download the sources, and build it yourself.

Testing Zimodem

Once the firmware has been installed on the module, you can open up the Serial Monitor in the Arduino IDE and verify it is running. You will need to set it to 1200 baud to match the default speed used by Zimodem, and have it set to “Carriage return“. You can type “AT” and it should respond with “OK”. You can type “AT+CONFIG” and it should startup the configuration process.

Zimodem startup banner, and entering the “AT+CONFIG” command.

If you get this far, you are ready to hook it up to the RS-232 to TTL adapter and then connect it to your computer.

WIRING

Simple 3-wire hookup

For simple serial ports, all you may need to do is hook up TX (transmit), RX (receive), VCC (3.3v) and GND (ground) between the ESP module and the TTL adapter. Here is the pinout of the NodeMCU ESP8266-12E module:

NodeMCU ESP8266-12E module pinouts.

All you have to do is connect the jumper wires between the pins of this module, and the matching pins on the TTL adapter. Some TTL adapters may have TX and RX reversed, but in general you want to hook up like this:

3-wire hookup:

    TTL         ESP8266
    ===         ==================
2   RX  <------ TX  GPIO1 (TX)
3   TX  ------> RX  GPIO3 (RX)
5   GND <------ GND GND
    VCC <------ 3V3 3.3V

For one of my adapters, I found it would not work using the 3.3V pin, and I had to switch to using the Vin (voltage input) pin, which would be the 5V coming off the USB connection. *THIS IS NOT RIGHT since the I/O pins of the ESP modules are mean to handle 3.3V and not 5V, so use caution. If you absolutely can’t get it to work on 3.3V, you can do what I did, but you risk frying the ESP.* I have other adapters that work properly at 3.3V.

It looks like this (note I am using the incorrect Vin instead of VCC):

ESP8266 to “3-wire” RS-232 TTL adapter.

WARNING! Keep all the bare metal pins from touching anything else! They could cause a short if they made contact with any metal. To reduce the chance of this happening, I used some of the non-conductive packing foam that the ESP module came in, and plugged the exposed pins into it:

To protect the exposed pins, I plugged them into the non-conductive packing foam that the part came in.

There are still a few exposed pins, and on the top side of the module are lots of metal parts and solder connections, so just make sure you keep away from any metal parts!

Now I was able to hook this up to my Color Computer’s Serial I/O port and load up an old terminal program and start using Zimodem.

Zimodem via Greg-E-Term on a Radio Shack Color Computer via the bitbanger Serial I/O port at 1200 baud.

RS-232 Challenges – Carrier Detect and Flow Control

A quick tidbit on RS-232…

There are nine lines used for RS-232. They go between the computer (DTE, data terminal equipment) to the device (DCE, data communication equipment). Prepare for many acronyms!

TX and RX: You can think of most lines as one-way paths, with some lines going from the computer to the device, and others going from the device to the computer. For instance, transmit (TX) from the computer goes one way to receive (RX) of the device. On the device, it’s transmit goes one way to the receive of the computer.

CTS and RTS: Some lines are used for flow control. Each device has a request to send (RTS) output line that goes to the other side’s clear to send (CTS) input line. CTS goes to RTS, and RTS goes to CTS, similar to have TX and RX and handled. For example, the computer turns on RTS (request to send) to tell the remote device it is okay to send data. The remote device reads this on it’s CTS (clear to send) pin. The reverse is also true, with the remote device’s RTS going to the computer’s CTS. Thus, if using flow control, the computer or device only send when their CTS (clear to send) line is active.

DCD: The device may also use carrier detect (DCD). For a telephone modem, when a call is connected, the device will turn on carrier detect. The computer can read the status of the DCD line to know if a connection is in progress.

RI: There is a ring indicator (RI) that was used by modems to indicate an incoming call. I’ve never used this at all, since the RS-232 interface I had back then wasn’t even wired for it.

DTR and DSR: I am less clear on how all these could be used, but in general, DTR was set by the computer to tell the remote device if it should hangup or not. The computer would “drop DTR” and that would force the modem to hangup. DSR is set by the device to indicate it is there and ready.

Here is a quick chart to explain them, specifically as how they are used by Zimodem:

 DTE (Comp.)        DCE (Modem)
 DB-9 Male          DB-9 Female
=============      =============
pin in    out      in    out pin
1   DCD <--------------- DCD   1
2   RX  <--------------- TX    2
3         TX  ---> RX          3
4         DTR ---> DTR         4
5   GND                  GND   5
6   DSR <--------------- DSR   6
7         RTS ---> CTS         7
8   CTS <--------------- RTS   8
9   RI  <--------------- RI    9

Some RS-232 interfaces require more than just TX and RX to be happy. The Color Computer’s RS-232 Pak, for example, uses a 6551 UART chip. This chip will not receive data unless it sees carrier detect (DCD). Old telephone modems would provide this DCD signal when a call was in progress, and drop the signal when the call ended This gave the computer a way to know if a connection was established or not. Unfortunately, this signal is not present in a 3-wire connection.

Faking carrier detect and flow control

It was possible to hook two computers together without a modem by using a NULL modem cable. These cables would swap TX and RX, so one computer’s transmit would end up at the other computer’s receive. They would also often do some trickery to force the DCD signal to be active. They did this by tying some of the pins on the RS-232 port together:

RS-232 port modification to make it operate without needing real DCD and other signals.

If we really don’t care about this missing lines (like CTS/RTS flow control, DTR/DSR, etc.), we can modify the RS-232 to TTL adapter so make it provide a fake DCD signal back to the computer.

Using the above diagram as a reference, I was able to solder a few pins together and use a short piece of wire to recreate it on real hardware:

Ugly soldering example of tying the DCD, DSR and DTR pins together, as well as CTS and RST.

This modification makes it so anytime the computer enables DTR, it will make DCD and DSR read as if they are enabled. It is creating a fake status by looping the DTR signal back into the DCD and DSR input pins.

Since this 3-wire hookup also does not have CTS and RTS, if the computer is expecting CTS (clear to send) to be active, that can never happen and thus it can never send. This modification ties the outgoing RTS (request to send) back to the incoming CTS (clear to send). When the computer enables request to send, to tell the remote device it is okay to send, it will read that same signal as if the remote device sent in it’s own request to send (coming in on the CTS line of the computer).

So much stuff.

Suffice it to say, but tying these lines together, it will fool the RS-232 device into thinking there is an active carrier detect and data terminal ready signal from the demote device anytime DTR is enabled. And, it will see a clear to send signal anytime it turns on read to send… Loopy goodness!

With that said, if you don’t want to solder, you could pick up these RS-232 jumper devices and create the connection this way. Note that in this example, I do not have CTS and RTS tied together. For my specific test, I did not need it, but other RS-232 interfaces may require it.

Minimal wiring required to get an RS-232 Pak to talk to a 3-wire RS-232 interface (TX, RX and GND).

5-wire hookup – Implementing real CTS/RTS flow control

Another option is to use an RS-232 to TTL adapter that actually provides more of these signals. For a bit more, you can find an adapter that has CTS and RTS as well:

“5-wire” RS-232 to TTL adapter, adding CTS and RTS for flow control.

By adding two more wires between Zimodem and the adapter, you can use real hardware flow control. Zimodem will only send when it sees a clear to send signal from the computer, and if Zimodem can’t handle all the data it is receiving, it will disable it’s request to send, so the computer’s CTS line indicates “stop sending me stuff!”

    TTL         ESP8266
    ===         ==================
2   RX  <------ TX  GPIO1 (TX)
3   TX  ------> RX  GPIO3 (RX)
5   GND <------ GND GND
7   RTS ------> D1  GPIO5  (CTS)
8   CTS <------ D2  GPIO4  (RTS)
    VCC <------ 3V3 3.3V

This configuration still would not work for my 6551-based RS-232 Pak. I would still need to fake the carrier detect.

Full-wire hookup – as real as it gets

The final, and best, solution is to use an RS-232 to TTL adapter that actually provides all the signals that Zimodem supports and that your RS-232 interface may require. This requires hooking up even more wires (ten total):

    TTL         ESP8266
    ===         ==================
1   DCD <------ D4  GPIO2 (DCD)
2   RX  <------ TX  GPIO1 (TX)
3   TX  ------> RX  GPIO3 (RX)
4   DTR ------> D6  GPIO12 (DTR)
5   GND <------ GND GND
6   DSR <------ D7  GPIO13 (DSR)
7   RTS ------> D1  GPIO5  (CTS)
8   CTS <------ D2  GPIO4  (RTS)
9   RI  <------ D5  GPIO14 (RI)
    VCC <------ 3V3 3.3V

Mine looks like this:

Wiring up a “full” RS-232 to TTL adapter.

If all those wires get to you, you can also do the same thing on a breadboard:

ESP8266 to RS-232 on a breadboard.

Configuring Zimodem: Commodore versus The World

Although the wiring seems complete, there is one final issue that needs to be solved.

Zimodem, when built for the ESP8266, inverts all the RS-232 signals. This is because that is how Commodore computers did it, and Zimodem was designed for Commodore users. Commodore inverts HIGH and LOW from the standard, so all signals have to be inverted in
Zimodem from their defaults. On Commodore, “HIGH” means active. For RS-232, “LOW” means
active.

What this means is even if you have the carrier detect wired up properly, Zimodem is going to send the opposite signal. When a connection is in progress, the signal will read as “no carrier” to a normal RS-232 interface. When Zimodem is ready to receive data, the request to send will look like the opposite.

This causes huge issues :)

If you are using my special build of Zimodem, you can skip this section. I already pre-configure my version as follows.

Fortunately, Zimodem is fully configurable. Using simple “AT” commands, you can change the behavior of any of the incoming or outgoing RS-232 signals that Zimodem uses. All you have to do is be able to send some commands and then save the Zimodem configuration. Here is the summary:

AT S Settings:
==============
0=HIGH is active (defualt).
1=LOW is active.
2=force HIGH
3=force LOW

Sig  SReg Default RS-232 Standard
===  ===  ======= =================
DCD  S46  0       1 (force LOW)
CTS  S48  0       1 (force LOW)
RTS  S50  0       1 (LOW is active)
RI   S52  0       1 (LOW is active)
DTR  S54  0       1 (LOW is active)
DSR  S56  0       1 (LOW is active)

You can set these commands one at a time, like:

ATS46=1
OK
ATS48=1
OK
...etc...

…but you may find that the moment you toggle one of them, you appear to be locked out. This is because the inverted defaults actually work to our advantage. On my interface, I need DCD before I can receive. Zimodem has no carrier, so it is sending out the inverted “there is no carrier” signal, which reads as “carrier detect” for me. The moment I “fix” that so it sends the normal signal, I suddenly have no carrier and can no longer receive data.

You may choose to send all the commands in one line:

ATS46=1S48=1S50=1S52=1S54=1S56=1

However, as soon as that is done, you may not see “OK”. Carrier detect is still flipped… You may be able to still send commands, but you would be typing blind if your interface requires DCD before it will receive. Because of this, I like to force DCD to be always on:

ATS46=3S48=1S50=1S52=1S54=1S56=1

That command flips everything, but makes sure DCD (S46) is forced low (3), so it appears like a carrier is always present. This lets me communicate with Zimodem at all times.

If I were running a BBS that relied on detecting carrier, I would have to leave that at S46=1 and just send commands blindly. (BUT, one of my old terminal programs, Greg-E-Term, is not coded in a way that makes this work. It seems if there is no DCD, it doesn’t let me send anything at all. Other terminal programs I have do not behave this way, so I consider it an issue with what GETerm was designed to do.)

Confusion Conclusion

With all of this said, there are probably still many omissions. A future article needs to be a summary of useful Zimodem commands and tutorials on how to use it.

I also want to cover another alternate approach to having to configure with all those ATS commands. In my case, I simple modified the source code so the version I built had them setup the normal way so I never had to do any configuration.

And I need to document how to just install a binary without using Arduino IDE.

Until then… Comments greatly appreciated.

Building Zimodem for ESP-32 with USB console support

If you are using a NodeMCU-32S module like the one I ordered from Amazon:

HiLetgo ESP-WROOM-32 ESP32 ESP-32S Development Board 2.4GHz Dual-Mode WiFi + Bluetooth Dual Cores Microcontroller Processor Integrated with Antenna RF AMP Filter AP STA for Arduino IDE https://www.amazon.com/…/B…/ref=cm_sw_r_cp_tai_X5iFAbW6CD3ZJ

…you may want todo a few tweaks to the ZIMODEM. ZIMODEM is setup to build for Tools->Board->NodeMCU-32S.

There are two major differences in building Zimodem for the ESP8266 and the ESP-32:

  1. The ESP-32 ZIMODEM has more functionality. There are multiple serial ports on the module, and more I/O pins. By default, the ESP-32 build will have a separate debug port (the USB console) from the communication (the TX/RX pins it uses). If you want to use the USB terminal for testing, rather than debug output, you can make two quick hacks:
    1. In zmodem.ino at around line 43, disable the debugPrintf as follows:
      //#define debugPrintf Serial.printf
      #define debugPrintf doNothing
      

      That will make it use the ESP32 code, and disable debug output.

    2. In pet2asc.h, comment out the Hardware Serial port initialization and make it use use the standard Serial port:
      //static HardwareSerial HWSerial(2);
      #define HWSerial Serial
      

      That will make the HWSerial port be the same one used by the USB console.

There is probably a better way, but this was the first time I got it going.

After that, the build you make will be controllable via USB port or the RS-232 port.