' B7AB3EDA542BA398604FDBFBD724B49CC92BAEBA467FC6B42F179DD144212706C0756D59ACD0BE12A4CB00D320906441E88FCBCCBBBE0385921AB2E88510844F ' sRipeTech ' 2C102C09B9 2025-06-05 16:53:39 ' ######################################################################################## ' Adafruit MCP2221 breakout board ' driving an eletechsup DM43B04 ' ' A script written for PlodWare Scripter ' 2025-06-03 ' ######################################################################################## ' This demo uses a minimal ammount of code to provide the ' access to 2 of the functions exposed by the MCP2221A DLL ' to support driving the eletechsup DM43B04 4-digit 7-segment display board. ' --------------------------------------------------------- ' The following reflects my (quite likely incomplete, or even incorrect) understanding ' of the 7-segment display board marked as ' eletechsup DM43B04 ' --------------------------------------------------------- ' The MCP2221A DLL expects the Mcp2221_I2cWrite interface to have an i2c address. ' The address is (for 7-bit devices) shifted 1 bit to the left, and then the ' least significant bit is set to 0 (for a write operation). ' ' This does not seem to be consistant with the DM43B04. ' ' Whilst the DM43B04 is a "sort" of i2c device it has some unique aspects. ' It does NOT really have an i2c address. ' ' Every DM43B04 command consists of two bytes: ' a command code, followed by a data byte ' ' ***Fortunately*** the command codes all have bit-0 = 0 ' ' So when we use the Mcp2221_I2cWrite interface, we pass it ' A command byte - which we shift RIGHT one bit, and pretend that it is the i2c address. ' And a data byte - unchanged. ' see function SSegWr below. ' --------------------------------------------------------- ' Here are the DM43B04 commands: ' display off: 0x48 , 0x00 ' display on: 0x48 , 0x01 ' brightness of 7 segments: ' 0x48 followed by one of Dim 0x11, 0x21,..0x71, 0x01 bright ' brightness of 8 segments (seems to automatically turn the decimal point on as well): ' 0x48 followed by one of Dim 0x19, 0x29,..0x79, 0x09 bright ' set left most display : 0x68 , 0x?? where ?? is a bit map of the 8 display parts. See below. ' : 0x6A , 0x?? ' : 0x6C , 0x?? ' set right most display: 0x6E , 0x?? ' --------------------------------------------------------- ' A display character consists of 8 parts: x=decimal point, plus 7 bars (a..g) ' ' -a- ' f | | b ' -g- ' e | | c ' -d- x ' ' We combine these 8 parts in to a single byte: 0x0xgfedcba ' --------------------------------------------------------- newscript report() dim MCP_defaultVID = 0x4D8 dim MCP_defaultPID = 0x0DD dim mcpDLL = dll.open ("mcp2221_dll_um_x64") IF ( ! mcpDLL ) THEN report ( "MCP: Could not open the DLL file." ) STOP END IF ' void* Mcp2221_OpenByIndex(unsigned int VID, unsigned int PID, unsigned int index) dim _MCP_OpenByIndex = dll.link(mcpDLL, "Mcp2221_OpenByIndex", 3,"unsigned" ) ' int Mcp2221_I2cWrite(void* handle, unsigned int bytesToWrite, unsigned char slaveAddress, ' unsigned char use7bitAddress, unsigned char* i2cTxData) dim _MCP_I2CWrite = dll.link(mcpDLL, "Mcp2221_I2cWrite" , 5,"signed32" ) ' request access to the 0'th device. dim mcp_Handle = _MCP_OpenByIndex ( MCP_defaultVID , MCP_defaultPID , 0 ) IF ( mcp_handle == -1 ) then report ( "MCP: Could not connect to target device." ) STOP END if ' --------------------------------------------------------- FUNCTION SSegWr ( p0 , p1 ) dim outBytes = byteArray (1,p1) _MCP_i2cWrite ( mcp_handle , 1 , p0 rshift 1 , 7, outbytes) END function ' --------------------------------------------------------- SSegWr( 0x48 , 0x00) SSegWr( 0x48 , 0x01) ' enable display SSegWr( 0x48 , 0x31) ' set brightness (lowish!) ' clear the display SSegWr( 0x68 , 0)' left-most display SSegWr( 0x6A , 0) SSegWr( 0x6C , 0) SSegWr( 0x6E , 0)' right-most display sleep ( 1 * 1000) ' wait for 1 second ' display "HELP" SSegWr( 0x68 , 0b01110110)' left-most display SSegWr( 0x6A , 0b01111001) SSegWr( 0x6C , 0b00111000) SSegWr( 0x6E , 0b01110011)' right-most display sleep ( 5 * 1000) ' wait for 5 seconds ' display "1.234" SSegWr( 0x68 , 0b10000110)' left-most display, most significant bit=1=decimal point SSegWr( 0x6A , 0b01011011) SSegWr( 0x6C , 0b01001111) SSegWr( 0x6E , 0b01100110)' right-most display sleep ( 5 * 1000) ' wait for 5 seconds ' display " End" SSegWr( 0x68 , 0 )' left-most display SSegWr( 0x6A , 0b01111001) SSegWr( 0x6C , 0b01010100) SSegWr( 0x6E , 0b01011110)' right-most display