Thats it! My servo controller code for one servo is ready. when it becomes 1, first we have to clear the flag by ourselves (line 26) then we can get last written byte to b1 (line 27) and deside what to do with it upon address it was written to (lines 29-32). Line 22: We continiously poll the hi2cflag to see if master wrote something to us. Line 17-18: initialize scratchpad byte 0 with value of 150 (servo center position) and move servo into that pos. We have 160 there as bit0 of address is read/write flag which is ignored in our case, so to shift 80 one bit to the left we have to muliply it by 2, that gives us 160. Line 15: setup Picaxe as I2C slave with adress 80. You can add more controls by just adding case branches for other servos or whatever you desire!ġ5 hi2csetup i2cslave, 160 '80 on arduinoĢ7 get hi2clast, b1 ' get last byte writtenĢ9 select case hi2clast 'what address in scratchpad it was written toģ1 servopos 0, b1 'which is our servo 0 slot. My Picaxe I2C slave code for use of byte 0 of scratchpad to control servo on outpin 0. Arduino has pullup resistors for I2C built-in, so you do not need to mess around with resistors. To connect 2 mCUs you need just 2 wires: Picaxe 28x1 pin 14 (i2c clock) to Arduino analog input 5 and Picaxe pin 15 (i2c data) to Arduino analog input 4. My setup: Picaxe 28x1 on breadboard + Arduino Duemilanove. Sounds very promising to me! So lets get started. hi2cflag flag set when master writes to our chip.Giving all 128 (X1, 20X2) or 256 (X2) bytes of scratchpad area for memory transfer.should not be any interference with servo command for example) I2C functions absolutely automatic (i.e.Ability to configure Picaxe as I2C slave (for 20x2, 28x1, 28x2, 40x1 and 40x2 chips only).TARAM!!! hi2csetup command just gives you all you need!!! : Picaxe 28x1 chip? Which will communicate over serial.Doh!. So, I thought: What about making my own servo controller of say. While working on my first Arduino project I found out that servo library is not compatible with software serial library which is very bad for my project.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |