<div dir="auto">You should be able to use the library from Pascal directly rather than trying to recreate it from scratch. <div dir="auto"><br></div><div dir="auto">Jeff </div></div><br><div class="gmail_quote"><div dir="ltr">On Sun, Jul 29, 2018, 10:20 AM Anthony Walter <<a href="mailto:sysrpl@gmail.com">sysrpl@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I'm not sure what would be the correct list for this question since it involves writing Pascal code and not Lazarus, so here goes ...<div><br></div><div>Can anyone offer me any advice or refer me to helpful resources on the subject of using Pascal code to <a href="https://www.youtube.com/watch?v=fh2QcmcBRpQ" target="_blank" rel="noreferrer">control WS2128 led strips</a>, or neopixels, from a Raspberry Pi?</div><div><br></div><div>I've wired up a <a href="https://www.amazon.com/gp/product/B072N7VGK6/ref=oh_aui_detailpage_o02_s01?ie=UTF8&psc=1" target="_blank" rel="noreferrer">some neopixels</a> and am able to control them by way of PWM (pulse wave modulation) on GPIO 18 (pin 12 on a Pi 3) using <a href="https://github.com/jgarff/rpi_ws281x" target="_blank" rel="noreferrer">this rpi_ws281x git repository</a>. It works great either in C or using Python bindings, and I am able to create effects in C code easily. But obviously I'd prefer to interface with the neopixels using Pascal.</div><div><br></div><div>I've seen some Pascal libraries for both GPIO access, and DMA pin mapping, but the communication protocol for controlling <span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">neopixels is a bit more complex than writing a 24 bit value to a pin. Each pixel can be controlled in both brightness and color, though I'm unsure how the wx281x library is doing this.</span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Assuming I was to do this in from scratch Pascal, that is control the colors and brightness of many pixels withing an entire neopixel strip, I believe I need to do the following in psuedo code.</span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"> // open device memory</span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"> fd = open('/dev/mem')</span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"> // map the file descriptor to the memory address of <span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">gpio18</span></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"> gpio18</span> = mmap(fd, ...)</span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"> // fd is no longer needed</span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"> close(fd)</span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"> </span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"> [ then write to <span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">gpio18 in some loop as a data structure ]</span></span></div><div> </div><div> // cleanup</div><div> unmap(<span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">gpio18</span>)</div><div><br></div><div>If that psuedo code is the correct way to do things, I would need to know what is the offset and page size for PWM GPIO18, what flags to use with mmap, and finally what memory locations inside of the <span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">gpio18 pointer control which pixel, what is the brightness memory location and size, what is the color <span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">memory</span><span style="text-decoration-style:initial;text-decoration-color:initial"> location and size for each pixel. Also, is there any other memory location inside <span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">gpio18 that is of importance or relevance, such as an on/off bit?</span></span></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></span></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Does anyone have any insight into this subject that might be useful? After I get something that works I'll be sure to share the resulting Pascal code and a video plus tutorial.</span></span></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></span></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">TIA</span></span></span></div></div>
_______________________________________________<br>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank" rel="noreferrer">fpc-pascal@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal" rel="noreferrer noreferrer" target="_blank">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a></blockquote></div>