Announcement

Collapse
No announcement yet.

OLED Logic Issues

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • HeyItsPatrick
    replied
    That solves my problem exactly. Again, thank you so much for your help.

    Patrick

    Leave a comment:


  • pauleilio
    replied
    Hi Patrick,

    I made this bit of code to convert two 8bit binary numbers to one value. The only problem is that the binary strings have to be 8 chars so it might be best to create an array from the sent ASCII string.

    Code:
     var a[8];
        var v;
        var n;
        var value;
        to(a);print("00000000");
        to(APPEND);print("00000010");
        v := 0x8000;
        for(n := 0; n < 8; n ++)
        if((a[n] & 0xff)== 49) value := value + v;
        v := v >> 1;
        if((a[n] >> 8)== 49) value := value + v;
        v := v >> 1;
        next
        print(value);
    It puts together two 8 bit binary strings into one 16 character string and then converts the whole 16 to a value.

    Best regards

    Paul

    Leave a comment:


  • HeyItsPatrick
    replied
    I have a secondary piece of hardware that I use to verify the output of the microcontroller. I'm a bit more interested in converting from an ASCII string to its numerical value. Even just using the terminal, I cannot get anything to return better than 00 without just assigning literal binary values where I need them. I suspect this is due to serin(). If I understand correctly, serin() is just going to assemble a string of the sent input, or rather, allow for the creation of a character array containing the characters sent as input to the OLED. Unless I am way off here or I am missing something, it would appear the final piece to this puzzle lies in conversion from an ASCII char array to each element's respective numerical value.

    Leave a comment:


  • pauleilio
    replied
    Hi Patrick,

    You could connect the micro-controller to the Terminal in Workshop which is under the Tools tab. The programming adapter for the display could be connected to the micro-controller for this test. This will show exactly what is being sent and you could also post a screen shot here so we know how best to handle the data.

    Best regards

    Paul

    Leave a comment:


  • HeyItsPatrick
    replied
    Well, I managed to get it consistently and properly working with the array and everything. Still not working with the microcontroller, but I suspect that is now an issue with that particular piece of hardware, not the code nor the oled. Just in case I have been misinformed, and the microcontroler is actually putting out ASCII, I would appreciate it if you could let me know if you find anything on how to convert from an ASCII string of binary to a real number. Thanks for the help.

    Leave a comment:


  • HeyItsPatrick
    replied
    No, it's being sent as raw binary. My initial approach was actually to try and treat it as/convert it to a string literal and manipulate that, instead of trying to manipulate the raw binary values, and that did not produce anything viable.

    Leave a comment:


  • pauleilio
    replied
    Hi Patrick,

    Thanks for the information, Yes you did mention the type of display / processor you are using so that is all ok. If binary is being sent as "10101010" (170) as ASCII text then yes we would have to convert this to a real number first. There wont be a built in command to do this but I will do some testing.

    Best regards

    Paul

    Leave a comment:


  • HeyItsPatrick
    replied
    The input would come from the microcontroller via a UART cable. I must not have mentioned that I am doing all this on a uOLED 96 G2

    Leave a comment:


  • pauleilio
    replied
    Hi Patrick,

    Yes this code is the problem,

    var a,b;
    //a := input_Data[2];
    //b := input_Data[3];
    to(a);print([BIN]input_Data[2]);
    to(b);print([BIN]input_Data[3]);
    value:= a << 8|b;

    This line ' to(a);print([BIN]input_Data[2]);' is trying to create a string of the binary so we can't use 'value:= a << 8|b;' to convert to a value.

    I will work with this part, when you say the microcontroller is pushing out binary can you explain a bit more how this will arrive at the display.

    Best regards

    Paul




    Leave a comment:


  • HeyItsPatrick
    replied
    Also, I spoke too early. It's still not returning anything besides 00 to COM0, or its still the wrong output. Just didn't look closely enough originally. Maybe I'm massively wrong here, I'll drop you my code.
    Given input of 01110114EA1B via the terminal, its looking to pull 14EA from the input, convert it to BIN because that's what the real microcontroller will be sending it as, and then converting it to decimal and outputting it. Now, I know it can pull the values just fine, because when I output them to COM0, it does what it's suppoesed to, every time. It's the conversion part that is really mucking up everything and I have no idea why, as I've tried many different ways, and they seem to work for everyone but me. Maybe you can help here. Thanks for everything.


    Code:
    #platform "GOLDELOX"
    #inherit "4DGL_16bitColours.fnc"
    #inherit "VisualConst.inc"
    #inherit "NoName1Const.inc"
    #inherit "PrintDiskGoldelox.inc"
    #inherit "LedDigitsDisplayGoldelox.inc"
    
    func main()
        print("Starting\n") ;
        while(!media_Init())
            putstr("Drive not mounted...");
            pause(200);
            gfx_Cls();
            pause(200);
        wend
        var buffer[48], input;
        repeat
            repeat
            pokeW(TIMER0, 5000);
                setbaud(BAUD_9600);
                com_Init(buffer, 48, 0);
                var input_Data[10];
                var value:="";
                repeat
                    while ( (input := serin()) >= 0)
                        if(input == 0x01) //if 0h01 has been sent to indicate that the input is writing to an object
                            var count:=0;
                            while((input:=serin())>=0)
                                input_Data[count] := input;
                                to(COM0);print([HEX2]input_Data[count]);
                                count++;
                                if(input==0x1B) break;
                            wend
    
                            switch (input_Data[0])
                                case 0x11:
                                    //txt_MoveCursor(input_Data[1]-1,7);
                                    txt_MoveCursor(5,0);
                                    break;
                                case 0xA2:
                                    break;
                                case 0xA3:
                                    break;
                            endswitch
                //Everything up until here works just fine, in terms of itself. Maybe it's interacting weird with this later code
                            value:=0;
                            //to(COM0);print([BIN]input_Data[2],[BIN]input_Data[3]); //now we have the whole BIN value concatted together
                            //The above line woorks when I send it to COM0, but not if I try and use to(value);
                            txt_MoveCursor(0,0);
                            //if(TRUE)
                                var a,b;
                                //a := input_Data[2];
                                //b := input_Data[3];
                                to(a);print([BIN]input_Data[2]);
                                to(b);print([BIN]input_Data[3]);
                                value:= a << 8|b;
                                to(COM0);print(value);
                            //endif
                        endif
                    wend
    
                until (!peekW(TIMER0));           // loop until TIME_OUT register is 0
    
                if (com_Full()) print("Buffer Full ");
                if (com_Error()) print("Comms Error ");
    
                pause(3000);
            until ( com_Full() || com_Error() );      // reset if error occurred
        forever
    endfunc

    Leave a comment:


  • HeyItsPatrick
    replied
    Am I not allowed to use to() on a var that has not been initalized? I want to condense my code and the whole thing breaks when I don't initialize a or b

    Leave a comment:


  • HeyItsPatrick
    replied
    woops, I was freehanding the var names a bit so our code would look more similar and we both could keep vars and things straight. Looks like I forgot to swap everything in my rush. I got it working by writing the BIN values from the array using to(). So i ended up with

    to(a); print([BIN] input[0]);

    since just going right from the array to a new var didn't appear to work at all.

    Thanks for the help
    Patrick

    Leave a comment:


  • pauleilio
    replied
    Hi,

    It is just a typo which is making it fail. I have modified your example, you won't need var msb, lsb; if you have already declared them elsewhere

    var a,b;
    var msb, lsb;
    msb := input[0];
    lsb := input[1];
    num := msb << 8 | lsb;
    to(COM0);print([DEC] num);

    Best regards

    Paul

    Leave a comment:


  • HeyItsPatrick
    replied
    Thanks.
    The code works fine for literals, but for some reason it's having trouble with using array elements instead. for example, this outputs just 00

    var a,b;
    msb := input[0];
    lsb := input[1];
    num := msb << 8 | lsb;
    to(COM0);print([DEC] val);

    Leave a comment:


  • pauleilio
    replied
    Hi,

    Sorry about that, I tried it with a Diablo as I didn't have a Goldelox to hand but I have tried it now with a Goldelox and if(FALSE) works fine for me. Not sure why it would fail on your display.

    If I understand correctly, you can use this code to concatenate the 2 bytes into 1 single number,

    var num;
    var msb := 1;
    var lsb := 10;
    num := msb << 8 | lsb

    num would equal 266;

    Paul

    Leave a comment:

Working...
X