hallo Kampi.
hast recht ,ich habs I2C init vergessen.hab es geändert.
das programm startet den I2C und damit die motoren ,soweit sogut- nur den Ultraschallsensor danach und dessen ausgabe,der teil startet nicht!
fehlt da eine anweisung??
mfg jörg
hallo Kampi.
hast recht ,ich habs I2C init vergessen.hab es geändert.
das programm startet den I2C und damit die motoren ,soweit sogut- nur den Ultraschallsensor danach und dessen ausgabe,der teil startet nicht!
fehlt da eine anweisung??
mfg jörg
Bis wohin läuft das Programm den? Mach das mal mit Print-Befehlen und schau wo das Programm stehen bleibt.
Schaut ruhig mal auf meiner Homepage vorbei:
http://kampis-elektroecke.de
Oder folge mir auf Google+:
Daniel Kampert
Es gibt 10 Arten von Menschen. Die einen können Binär, die anderen nicht.
Gruß
Daniel
hab es im code oben rot markiert wieweit es läuft(bis hierher läuft es -dann ist schluss!) .
hmm....mit dem print befehl geb ichs doch aufm terminal aus-oder lieg ich da falsch? ich nutze aber das lcd-display als ausgabe!
das zeigt mir "RN-Control V1.4 " und "fahrprog" an.das bleibt dann auch auf dem lcd display stehen und die motoren laufen an.das ist wie gesagt alles in ordnung so.nachdem dann die 20 sec oder so rum sind in denen die motoren laufen sollen,soll er über RS232 den Ultraschallsensor abfragen bzw auf dem lcd display die entfernung ausgeben- das aber macht er nicht.....
mfg jörg
So ich hab nochmal in der Doku geschaut. In der Doku vom SRF02 steht folgendes Programm:
Dort verwenden sie die Adresse 0. Ich nehme nicht an das du die Adresse geändert hast? (siehst du an dem Blinken der LED nach dem Einschalten).Code:Declare Function Srf02_firmware(byval Slaveid As Byte) As Byte Declare Function Srf02_entfernung(byval Slaveid As Byte) As Integer $regfile = "m32def.dat" $framesize = 42 $swstack = 42 $hwstack = 42 $crystal = 16000000 'Quarzfrequenz $baud = 9600 'Normale Hardware RS232 (hier hängt PC dran) Open "COMA.0:9600,8,N,2" For Output As #1 'Port PA0 wird als TX definiert Open "COMA.1:9600,8,N,2" For Input As #2 'Port PA1 wird als RX definiert Const Srf02_slaveid = 0 'Standard RS232 Slave ID von SRF02 Dim Entfernung As Integer Wait 3 'Warte 3 Sekunden Print "SRF02 RS232 Testprogramm von robotikhardware.de" Print "SRF02 Ultraschall-Firmware Version:" ; Srf02_firmware(srf02_slaveid) Print "PA0 wird TX und PA1 wird als RX genutzt" V = 1 Do Entfernung = Srf02_entfernung(srf02_slaveid) Print "Entfernung:" ; Entfernung ; "cm" Wait 1 Loop End '------------- Hilfsfunktionen für SRF02 ---------- Function Srf02_firmware(byval Slaveid As Byte) As Byte Print #1 , Chr(slaveid) ; Chr(93); Srf02_firmware = Waitkey(#2) End Function Function Srf02_entfernung(byval Slaveid As Byte) As Integer Local Lob As Byte Local Hib As Byte Print #1 , Chr(slaveid) ; Chr(84); 'Messvorgang in cm starten Inputbin #2 , Hib , Lob 'Warte auf Ergebnis Srf02_entfernung = Makeint(lob , Hib) End Function
Schaut ruhig mal auf meiner Homepage vorbei:
http://kampis-elektroecke.de
Oder folge mir auf Google+:
Daniel Kampert
Es gibt 10 Arten von Menschen. Die einen können Binär, die anderen nicht.
Gruß
Daniel
ich hab den sensor mal im I2C mode benutzt und da seine id geändert-wollte ja eigentlich 2 davon verbauen,deswegen.
jetzt hab ich aber am I2C den motortreiber dran und wollte deswegen den us sensor am RS232 nutzen.
ich hab auch dieses beispielprog welches du zeigst ,am laufen,mit id=1,also daran denk ich liegts nicht.mit id=0 passiert mit diesem sensor nix mehr,da müsst ich mal den anderen probieren...die werte die der erste mit id=1 ausgibt sind auch korrekt.
mfg jörg
Wieso verwendest du Soft-UART ?
Ich wette, dein Porgramm steckt hier:
Code:Inputbin #2 , Hib , Lob 'Warte auf Ergebnis
mfg robert
Wer glaubt zu wissen, muß wissen, er glaubt.
ok.warum? ich hab den teil aus der demo übernommen-die demo ist gleiche die auch kampi gepostet hat.
mfg jörg
Geändert von highblackbon (12.12.2011 um 10:00 Uhr)
hallo
um das thema mal hier abzuschliessen:
ich hab den srf02 und das rn motorcontrol über I2C mit dem rn control verbunden.
mit diesem ersten einfachen code läuft das ganze:
Declare Function Srf02_firmware(byval Slaveid As Byte) As Byte
Declare Function Srf02_entfernung(byval Slaveid As Byte) As Integer
$regfile = "m32def.dat"
$framesize = 60
$swstack = 60
$hwstack = 60
$crystal = 16000000 'Quarzfrequenz
'''''''''''''''''''''lcd''''''''''''''''''
Config Lcd = 20 * 4 'wir verwenden ein 4 x 20 Zeichen Display
Cursor On
' Im I/O Mode wird jeder Prozessor Pin einzeln angegeben
Config Lcdpin = Pin , Db4 = Portb.0 , Db5 = Portb.1 , Db6 = Portb.2 , Db7 = Portb.3 , E = Portb.5 , Rs = Portb.4
Config Scl = Portc.0 'Ports fuer IIC-Bus
Config Sda = Portc.1
Dim Entfernung As Integer
Dim V As Byte
Cls
Locate 2 , 3
Lcd "moin chef"
Waitms 900
Cls
Locate 1 , 1
Lcd "RN-CONTROL V1.4 "
Cls
Waitms 800
Locate 2 , 6
Lcd "Fahrprog1"
Wait 1
I2cinit
Const Srf02_slaveid = &HE2
Cls
Locate 1 , 1
Lcd "SRF02 Ultraschall-Firmware Version:" ; Srf02_firmware(srf02_slaveid)
Wait 1
V = 1
Do
I2cinit
I2cwbyte &HE2 'Standard I2C Adresse von SRF02
Entfernung = Srf02_entfernung(srf02_slaveid)
Cls
Locate 2 , 1
Lcd "Entfernung:" ; Entfernung ; "cm"
Waitms 65
If Entfernung < 27 Then Gosub Hind
Cls
Locate 2 , 5
Lcd "vorwaerts..."
I2cstart
I2cwbyte &H58
I2cwbyte 35 'Kennung
I2cwbyte 5 'Befehl
I2cwbyte 3 'Motorwahl
I2cwbyte 1 'Richtung
I2cstop
Waitms 500
I2cstart 'Motor 1 starten (Geschwindigkeit=45
I2cwbyte &H58
I2cwbyte 35 'Kennung
I2cwbyte 2 'Befehl
I2cwbyte 1 'Motorwahl
I2cwbyte 195 'Geschwindigkeit
I2cstop
Waitms 250
I2cstart 'Motor 2 starten (Geschwindigkeit=45
I2cwbyte &H58
I2cwbyte 35 'Kennung
I2cwbyte 2 'Befehl
I2cwbyte 2 'Motorwahl
I2cwbyte 175 'Geschwindigkeit
I2cstop
Loop
End
'''''''''''''''''''''
Hind:
I2cstart
I2cwbyte &H58
I2cwbyte 35 'Kennung
I2cwbyte 2 'Befehl
I2cwbyte 3 'Motorwahl
I2cwbyte 0 'Geschwindigkeit
I2cstop
Waitms 500
I2cstart 'Motor Rechts drehen
I2cwbyte &H58
I2cwbyte 35 'Kennung
I2cwbyte 5 'Befehl
I2cwbyte 3 'Motorwahl
I2cwbyte 0 'Richtung
I2cstop
Waitms 100
I2cstart
I2cwbyte &H58
I2cwbyte 35 'Kennung
I2cwbyte 2 'Befehl
I2cwbyte 3 'Motorwahl
I2cwbyte 175 'Geschwindigkeit
I2cstop
Wait 2
I2cstart
I2cwbyte &H58
I2cwbyte 35 'Kennung
I2cwbyte 2 'Befehl
I2cwbyte 3 'Motorwahl
I2cwbyte 0 'Geschwindigkeit
I2cstop
'motor2 starten andersrum
I2cstart 'Motor Rechts drehen
I2cwbyte &H58
I2cwbyte 35 'Kennung
I2cwbyte 5 'Befehl
I2cwbyte 1 'Motorwahl
I2cwbyte 0 'Richtung
I2cstop
I2cstart
I2cwbyte &H58
I2cwbyte 35 'Kennung
I2cwbyte 2 'Befehl
I2cwbyte 1 'Motorwahl
I2cwbyte 185 'Geschwindigkeit
I2cstop
Waitms 250
I2cstart 'Beide Motoren Rechts drehen
I2cwbyte &H58
I2cwbyte 35 'Kennung
I2cwbyte 5 'Befehl
I2cwbyte 2 'Motorwahl
I2cwbyte 1 'Richtung
I2cstop
Waitms 250
I2cstart
I2cwbyte &H58
I2cwbyte 35 'Kennung
I2cwbyte 2 'Befehl
I2cwbyte 2 'Motorwahl
I2cwbyte 195 'Geschwindigkeit
I2cstop
Wait 4
I2cstart
I2cwbyte &H58
I2cwbyte 35 'Kennung
I2cwbyte 2 'Befehl
I2cwbyte 3 'Motorwahl
I2cwbyte 0 'Geschwindigkeit
I2cstop
Wait 1
Return
'------------- Hilfsfunktionen für SRF02 ----------
Function Srf02_firmware(byval Slaveid As Byte) As Byte
Local Firmware As Byte
Local Slaveid_read As Byte
Slaveid_read = Slaveid + 1
I2cstart
I2cwbyte Slaveid
I2cwbyte 0 'Leseregister festlegen
I2cstop
I2cstart
I2cwbyte Slaveid_read
I2crbyte Firmware , Nack
I2cstop
Srf02_firmware = Firmware
End Function
Function Srf02_entfernung(byval Slaveid As Byte) As Integer
Local Lob As Byte
Local Hib As Byte
Local Firmware As Byte
Local Temp As Byte
Local Slaveid_read As Byte
Slaveid_read = Slaveid + 1
'Messvorgang in starten
I2cstart
I2cwbyte Slaveid
I2cwbyte 0
I2cwbyte 81 'in Zentimetern messen
I2cstop
Waitms 65 'minimale Wartezeit für Messung bei SRF02
I2cstart
I2cwbyte Slaveid
I2cwbyte 2 'Leseregister festlegen
I2cstop
I2cstart
I2cwbyte Slaveid_read
I2crbyte Hib , Ack
I2crbyte Lob , Nack
I2cstop
Srf02_entfernung = Makeint(lob , Hib)
End Function
mfg jörg
Lesezeichen