hi,
I have the Redpark Serial Cable C2-TTL (
http://www.robotshop.com/content/images/redpark-iphone-ttl-serial-adapter.jpg)
and i use the book: iOS Sensor Apps with Arduino, but it doesn´t works!
Here is my Code!
#import "ViewController.h"
#pragma mark - RscMgrDelegate methods
@interface ViewController ()
@end
@implementation ViewController
@synthesize textEntry;
@synthesize serialView;
@synthesize sendButton;
- (void)cableConnected:(NSString *)protocol{
[rscMgr setBaud:9600];
[rscMgr open];
}
- (void)cableDisconnected {
}
- (void)portStatusChanged{
}
- (void)readBytesAvailable:(UInt32)numBytes {
int bytesRead = [rscMgr read:rxBuffer Length:numBytes];
NSLog( @"Read %d bytes from serial cable.", bytesRead);
for(int i = 0;i < numBytes;++i) {
self.serialView.text = [NSString stringWithFormat:@"%@%c",
self.serialView.text,
((char *)rxBuffer)[i]];
}
}
- (BOOL) rscMessageRecevide:(UInt8 *)msg TotalLength:(int)len {
return FALSE;
}
- (void) didReceivePortConfig {
}
- (void)viewDidLoad
{
[super viewDidLoad];
rscMgr = [[RscMgr alloc] init];
[rscMgr setDelegate:self];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)sendString:(id)sender {
[self.textEntry resignFirstResponder];
NSString *text = self.textEntry.text;
int bytesToWrite = text.length;
for ( int i = 0; i < bytesToWrite; i++) {
txBuffer[i] = (int)[text characterAtIndex:i];
}
int bytesWritten = [rscMgr write:txBuffer Length:bytesToWrite];
}
@end
#import <UIKit/UIKit.h>
#import "RscMgr.h"
#define BUFFER_LEN 1024
@interface ViewController : UIViewController <RscMgrDelegate> {
RscMgr *rscMgr;
UInt8 rxBuffer[BUFFER_LEN];
UInt8 txBuffer[BUFFER_LEN];
UITextView *serialView;
UITextField *textEntry;
UIButton *sendButton;
}
@property (nonatomic, retain) IBOutlet UITextView *serialView;
@property (nonatomic, retain) IBOutlet UIButton *sendButton;
@property (nonatomic, retain) IBOutlet UITextField *textEntry;
- (IBAction)sendString:(id)sender;
@end
// The Arduino Code:
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop() {
while (Serial.available() <= 0) {
Serial.println("Hello World");
delay(300);
}
Serial.println("Bye World");
while(1) {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
}
I dont know what i do wrong and I hope you can help me!
thx!
byebye