New in pascal need help (raspberry pi SPI) lazarus / 1-Linux ---------------------------------------------------------------------- sabouras · 2016-12-12 10:35 I am currently working with the library libwiringpi which include some very useful functions. One of them is for the spi protocol of raspberry pi. This library has as prototype the function wiringPiSPIDataRW(channel:longint; data: Pointer; len:longint):longint;cdecl;external; Could please inform me how i could pass an array on the data section. Currently i try to make an array as buffer with 5 elements integer. I try many pointer example without success. The problem is i always take as result our of memory , or garbage from random memory position ( i think because i am not in medium or advance in pascal). The following code in C it works (i do not know if that helps). unsigned char buffer[3]; buffer[0] |= 0b11000000| ((adc_channel)<<4); printf("value to send is %d \n",buffer[0]); wiringPiSPIDataRW(spi_channel, buffer, 1); delay(2000);//wait to make the convertion wiringPiSPIDataRW(spi_channel, buffer, 3); result=buffer[1]<<7; result|=buffer[2]; final=result; final*=3.3; final/=4096; printf ("results = %f \n",final); printf("return value is %s \n",buffer); I am attaching the source code form my pascal program and the outputs form the C and the pascal program. I upload the attachment in following link http://www.filedropper.com/problemincode Any new ideas perhaps? ---------------------------------------------------------------------- Lulu · 2016-12-12 12:29 Hi ! I'm not an expert but, perhaps, you should try this : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);var    i:integer;                     //  because your  "adc_value" is only an index to browse "buffer" and not really an adc value,                                   //  this is clearer to call it "i" or whatever do you want  (in my opinion)    buffer:Array [0..2] of byte;     // [0..3] mean 4 byte length. You need only 3 bytes here    Res: longint;                    // this 2 variable replace your "result:double"    Value: double;begin memo1.clear; digitalWrite(CS,LOW); for i:=0 to 2 do                   // take care: only from 0 to 2 because we have now buffer[0..2]  buffer[i]:=0; //clean up array// prepare the code if channel_0.Checked                 // this is simpliest   then buffer[0] := $D0   else buffer[0] := $E0; digitalWrite(CS,LOW);//spi_test; Res := wiringPiSPIDataRW(spi_channel,@buffer[0],1);    // <- in Pascal language, "Result" is used to define the result of a function,                                                      //    so, better avoid using this as a variable delay(200);//wait for the convertion and setup time Res:=wiringPiSPIDataRW(spi_channel,@buffer[0],3); if Res=-1   then showMessage('Error in send and receive data'); Value:= (buffer[1] shl 7) or buffer[2]; digitalWrite(CS,HIGH);//stop convertions Value:=Value*3.3;//Vref=3.3 from rpi Value:=Value/4096;//2^10  adc output=(4096 *vin)/Vcc  vcc=vref=3.3//check for i:=0 to 3 do   memo1.lines.add('Buffer value '+intToStr(i)+' is '+IntToStr(Buffer[i])); memo1.lines.add('result = '+FloatToStr(Value));end;  I can't compile it because there isn't dll in your project. I hope this will help you. ---------------------------------------------------------------------- Xor-el · 2016-12-12 12:30 did you bother to check your previous question to see if it was answered or not?? *Thaddy Mode*  you asked the same question here http://forum.lazarus- ide.org/index.php?topic=35083 and some answers were provided. did you test if those answers worked for you? if no, then please continue the question in the previous topic.